Skip to content

Commit 3616e17

Browse files
authored
Merge pull request #3818 from Agenta-AI/fix/ui-improvements-editor-sidebar
fix(frontend): improve editor typography, heading hierarchy, sidebar sizing, and fix markdown scroll bug
2 parents ae99182 + 48909df commit 3616e17

File tree

7 files changed

+163
-55
lines changed

7 files changed

+163
-55
lines changed

web/oss/src/components/Editor/plugins/markdown/markdownPlugin.tsx

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,20 +123,47 @@ const MarkdownPlugin = ({id}: {id: string}) => {
123123
return editor.registerCommand(
124124
KEY_ENTER_COMMAND,
125125
(event) => {
126-
editor.update(() => {
127-
const selection = $getSelection()
128-
if (!$isRangeSelection(selection)) return false
129-
130-
const anchorNode = selection.anchor.getNode()
131-
const topNode = anchorNode.getTopLevelElementOrThrow()
132-
133-
if ($isCodeNode(topNode) && topNode.getLanguage() === "markdown") {
134-
event?.preventDefault()
135-
selection.insertRawText("\n")
136-
return true
137-
}
138-
})
139-
return true
126+
let handled = false
127+
editor.update(
128+
() => {
129+
const selection = $getSelection()
130+
if (!$isRangeSelection(selection)) return
131+
132+
const anchorNode = selection.anchor.getNode()
133+
const topNode = anchorNode.getTopLevelElementOrThrow()
134+
135+
if ($isCodeNode(topNode) && topNode.getLanguage() === "markdown") {
136+
event?.preventDefault()
137+
138+
// Save scroll position before inserting text to prevent
139+
// the browser from auto-scrolling to the bottom
140+
const rootElement = editor.getRootElement()
141+
const scrollContainer = rootElement?.closest(
142+
".agenta-editor-wrapper",
143+
) as HTMLElement | null
144+
const savedScrollTop = scrollContainer?.scrollTop ?? 0
145+
const savedElementScrollTop = rootElement?.scrollTop ?? 0
146+
147+
selection.insertRawText("\n")
148+
149+
// Restore scroll position after DOM update
150+
if (scrollContainer) {
151+
requestAnimationFrame(() => {
152+
scrollContainer.scrollTop = savedScrollTop
153+
})
154+
}
155+
if (rootElement) {
156+
requestAnimationFrame(() => {
157+
rootElement.scrollTop = savedElementScrollTop
158+
})
159+
}
160+
161+
handled = true
162+
}
163+
},
164+
{discrete: true},
165+
)
166+
return handled
140167
},
141168
COMMAND_PRIORITY_HIGH,
142169
)

web/oss/src/components/Playground/Components/Menus/SelectVariant/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ const SelectVariant = ({
304304

305305
// Normal mode: standard picker
306306
return (
307-
<div style={style ?? {width: 120}}>
307+
<div style={style ?? {width: 200}}>
308308
<EntityPicker<PlaygroundRevisionSelectionResult>
309309
variant="tree-select"
310310
adapter={adapter}

web/oss/src/styles/code-editor-styles.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.code-editor {
22
/* === Editor container === */
33
.editor-code {
4-
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
4+
font-family: "SF Mono", "JetBrains Mono", "Roboto Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
55
position: relative;
66
white-space: pre;
77
tab-size: 2;
@@ -10,7 +10,6 @@
1010
/* Initialize CSS counter for line numbers */
1111
counter-reset: line-number;
1212

13-
font-family: Menlo, Consolas, Monaco, monospace;
1413
display: block;
1514
line-height: 1.53;
1615
font-size: 13px;

web/oss/src/styles/editor-theme.css

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ h1 {
4141
max-width: 100%;
4242
color: #000;
4343
position: relative;
44-
line-height: 20px;
44+
line-height: 24px;
4545
font-weight: 400;
4646
text-align: left;
4747
border-top-left-radius: 10px;
@@ -98,10 +98,11 @@ h1 {
9898
}
9999

100100
.editor-text-code {
101-
background-color: rgb(240, 242, 245);
102-
padding: 1px 0.25rem;
103-
font-family: Menlo, Consolas, Monaco, monospace;
104-
font-size: 94%;
101+
background-color: rgba(221, 223, 225, 0.49);
102+
padding: 2px 0.35rem;
103+
font-family: "SF Mono", "JetBrains Mono", "Roboto Mono", Menlo, Consolas, Monaco, monospace;
104+
font-size: 90%;
105+
border-radius: 3px;
105106
}
106107

107108
.editor-link {
@@ -127,7 +128,7 @@ h1 {
127128

128129
.code-only .editor-code {
129130
background-color: rgb(240, 242, 245);
130-
font-family: Menlo, Consolas, Monaco, monospace;
131+
font-family: "SF Mono", "JetBrains Mono", "Roboto Mono", Menlo, Consolas, Monaco, monospace;
131132
display: block;
132133
padding: 8px 8px 8px 52px;
133134
line-height: 1.53;
@@ -184,23 +185,73 @@ h1 {
184185
}
185186

186187
.editor-heading-h1 {
187-
font-size: 18px;
188+
font-size: 28px;
188189
color: rgb(5, 5, 5);
189-
font-weight: 400;
190+
font-weight: 700;
190191
margin: 0;
192+
margin-top: 24px;
191193
margin-bottom: 12px;
192194
padding: 0;
193-
line-height: 1.5;
195+
padding-bottom: 8px;
196+
letter-spacing: -0.3px;
197+
line-height: 1.4;
198+
border-bottom: 1px solid #e0e0e0;
194199
}
195200

196201
.editor-heading-h2 {
197-
font-size: 15px;
198-
color: rgb(101, 103, 107);
199-
font-weight: 700;
202+
font-size: 24px;
203+
color: rgb(5, 5, 5);
204+
font-weight: 600;
205+
margin: 0;
206+
margin-top: 20px;
207+
margin-bottom: 10px;
208+
padding: 0;
209+
padding-bottom: 6px;
210+
line-height: 1.35;
211+
border-bottom: 1px solid #e0e0e0;
212+
}
213+
214+
.editor-heading-h3 {
215+
font-size: 20px;
216+
color: rgb(5, 5, 5);
217+
font-weight: 600;
218+
margin: 0;
219+
margin-top: 18px;
220+
margin-bottom: 8px;
221+
padding: 0;
222+
line-height: 1.35;
223+
}
224+
225+
.editor-heading-h4 {
226+
font-size: 18px;
227+
color: rgb(5, 5, 5);
228+
font-weight: 600;
229+
margin: 0;
230+
margin-top: 16px;
231+
margin-bottom: 6px;
232+
padding: 0;
233+
line-height: 1.35;
234+
}
235+
236+
.editor-heading-h5 {
237+
font-size: 16px;
238+
color: rgb(5, 5, 5);
239+
font-weight: 600;
240+
margin: 0;
241+
margin-top: 14px;
242+
margin-bottom: 4px;
243+
padding: 0;
244+
line-height: 1.35;
245+
}
246+
247+
.editor-heading-h6 {
248+
font-size: 14px;
249+
color: rgb(37, 37, 37);
250+
font-weight: 600;
200251
margin: 0;
201-
margin-top: 10px;
252+
margin-top: 12px;
253+
margin-bottom: 4px;
202254
padding: 0;
203-
text-transform: uppercase;
204255
line-height: 1.35;
205256
}
206257

web/oss/src/styles/globals.css

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ body {
6767
}
6868

6969
.editor-input > p {
70-
margin-top: 4px !important;
71-
margin-bottom: 4px !important;
70+
margin-top: 5px !important;
71+
margin-bottom: 8px !important;
7272
}
7373

7474
.hover-button-wrapper {
@@ -180,22 +180,26 @@ body {
180180

181181
.editor-inner:not(.code-editor) {
182182
.editor-code {
183-
background-color: rgb(240, 242, 245);
184-
font-family: Menlo, Consolas, Monaco, monospace;
183+
background-color: rgba(223, 224, 227, 0.28);
184+
font-family: "SF Mono", "JetBrains Mono", "Roboto Mono", Menlo, Consolas, Monaco, monospace;
185185
display: block;
186186
padding: 8px;
187187
line-height: 1.53;
188-
font-size: 13px;
188+
font-size: 13.5px;
189189
margin: 0;
190-
margin-top: 8px;
191-
margin-bottom: 8px;
190+
margin-top: 12px;
191+
margin-bottom: 12px;
192192
overflow-x: auto;
193193
position: relative;
194194
tab-size: 2;
195+
border-radius: 6px;
196+
border: 1px solid rgba(108, 112, 118, 0.05);
195197
}
196198

197199
> .editor-input.markdown-view > .editor-code {
198200
background-color: transparent;
201+
border: none;
202+
font-size: 14px;
199203
}
200204
> .editor-input:not(.markdown-view) > .editor-code {
201205
&:after {

web/oss/src/styles/tokens/antd-themeConfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@
924924
"lineWidth": 1,
925925
"lineHeight": 1.6666666666666667,
926926
"fontSizeLG": 14,
927-
"fontSize": 12,
927+
"fontSize": 13,
928928
"controlItemBgActive": "#f5f7fa",
929929
"controlHeightSM": 24,
930930
"controlHeightLG": 34,
@@ -944,12 +944,12 @@
944944
"itemSelectedBg": "#f5f7fa",
945945
"itemHoverColor": "#1c2c3d",
946946
"itemHoverBg": "rgba(5, 23, 41, 0.06)",
947-
"itemHeight": 28,
947+
"itemHeight": 32,
948948
"itemDisabledColor": "#bdc7d1",
949949
"itemColor": "#586673",
950950
"itemBorderRadius": 10,
951951
"itemBg": "#ffffff",
952-
"iconSize": 12,
952+
"iconSize": 14,
953953
"horizontalItemSelectedColor": "#1c2c3d",
954954
"horizontalItemSelectedBg": "rgba(0, 0, 0, 0)",
955955
"horizontalItemHoverColor": "#1c2c3d",

web/packages/agenta-ui/src/Editor/plugins/markdown/markdownPlugin.tsx

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,47 @@ const MarkdownPlugin = ({id}: {id: string}) => {
124124
return editor.registerCommand(
125125
KEY_ENTER_COMMAND,
126126
(event) => {
127-
editor.update(() => {
128-
const selection = $getSelection()
129-
if (!$isRangeSelection(selection)) return false
130-
131-
const anchorNode = selection.anchor.getNode()
132-
const topNode = anchorNode.getTopLevelElementOrThrow()
133-
134-
if ($isCodeNode(topNode) && topNode.getLanguage() === "markdown") {
135-
event?.preventDefault()
136-
selection.insertRawText("\n")
137-
return true
138-
}
139-
})
140-
return true
127+
let handled = false
128+
editor.update(
129+
() => {
130+
const selection = $getSelection()
131+
if (!$isRangeSelection(selection)) return
132+
133+
const anchorNode = selection.anchor.getNode()
134+
const topNode = anchorNode.getTopLevelElementOrThrow()
135+
136+
if ($isCodeNode(topNode) && topNode.getLanguage() === "markdown") {
137+
event?.preventDefault()
138+
139+
// Save scroll position before inserting text to prevent
140+
// the browser from auto-scrolling to the bottom
141+
const rootElement = editor.getRootElement()
142+
const scrollContainer = rootElement?.closest(
143+
".agenta-editor-wrapper",
144+
) as HTMLElement | null
145+
const savedScrollTop = scrollContainer?.scrollTop ?? 0
146+
const savedElementScrollTop = rootElement?.scrollTop ?? 0
147+
148+
selection.insertRawText("\n")
149+
150+
// Restore scroll position after DOM update
151+
if (scrollContainer) {
152+
requestAnimationFrame(() => {
153+
scrollContainer.scrollTop = savedScrollTop
154+
})
155+
}
156+
if (rootElement) {
157+
requestAnimationFrame(() => {
158+
rootElement.scrollTop = savedElementScrollTop
159+
})
160+
}
161+
162+
handled = true
163+
}
164+
},
165+
{discrete: true},
166+
)
167+
return handled
141168
},
142169
COMMAND_PRIORITY_HIGH,
143170
)

0 commit comments

Comments
 (0)