Skip to content

Commit 98b0ae9

Browse files
authored
fix: fix the editor issue where a cursor jumps to the top every time a code is updated (#1196)
fix the issue where the cursor on the editor jump as code is rewritten
1 parent 459b9e9 commit 98b0ae9

File tree

1 file changed

+31
-35
lines changed

1 file changed

+31
-35
lines changed

editor/EditorPanel.tsx

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -136,40 +136,36 @@ function EditorPanel(props: {
136136
if (props.onChange) props.onChange(newCode, language);
137137
}
138138

139-
const MonacoEditorWithResizer = () => {
140-
const { width, height, ref } = useResizeDetector<HTMLElement>();
141-
return (
142-
<div ref={ref} style={{ width: '100%', height: '100%' }}>
143-
<MonacoEditor
144-
// Refer to https://github.com/react-monaco-editor/react-monaco-editor
145-
width={width}
146-
height={height}
147-
language={language}
148-
value={code}
149-
theme={'gosling'}
150-
options={{
151-
autoClosingBrackets: 'beforeWhitespace',
152-
autoClosingQuotes: 'beforeWhitespace',
153-
cursorBlinking: 'smooth',
154-
folding: true,
155-
lineNumbersMinChars: 4,
156-
minimap: { enabled: true },
157-
scrollBeyondLastLine: false,
158-
wordWrap: 'on',
159-
lineNumbers: 'on',
160-
renderLineHighlight: 'line',
161-
renderIndentGuides: true,
162-
fontSize: 14,
163-
readOnly
164-
}}
165-
onChange={onChangeHandle}
166-
editorDidMount={editorDidMount}
167-
editorWillMount={editorWillMount}
168-
/>
169-
</div>
170-
);
171-
};
172-
173-
return <MonacoEditorWithResizer />;
139+
const { width, height, ref } = useResizeDetector<HTMLElement>();
140+
return (
141+
<div ref={ref} style={{ width: '100%', height: '100%' }}>
142+
<MonacoEditor
143+
// Refer to https://github.com/react-monaco-editor/react-monaco-editor
144+
width={width}
145+
height={height}
146+
language={language}
147+
value={code}
148+
theme={'gosling'}
149+
options={{
150+
autoClosingBrackets: 'beforeWhitespace',
151+
autoClosingQuotes: 'beforeWhitespace',
152+
cursorBlinking: 'smooth',
153+
folding: true,
154+
lineNumbersMinChars: 4,
155+
minimap: { enabled: true },
156+
scrollBeyondLastLine: false,
157+
wordWrap: 'on',
158+
lineNumbers: 'on',
159+
renderLineHighlight: 'line',
160+
renderIndentGuides: true,
161+
fontSize: 14,
162+
readOnly
163+
}}
164+
onChange={onChangeHandle}
165+
editorDidMount={editorDidMount}
166+
editorWillMount={editorWillMount}
167+
/>
168+
</div>
169+
);
174170
}
175171
export default EditorPanel;

0 commit comments

Comments
 (0)