Skip to content

Commit f5de841

Browse files
authored
fix(ui): relayout Monaco editor on window resize (#25784)
Signed-off-by: choejwoo <[email protected]>
1 parent c9a5a7e commit f5de841

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

ui/src/app/shared/components/monaco-editor.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const MonacoEditorLazy = React.lazy(() =>
3030
const Component = (props: MonacoProps) => {
3131
const [height, setHeight] = React.useState(0);
3232
const [theme, setTheme] = React.useState('dark');
33+
const editorApiRef = React.useRef<monacoEditor.editor.IEditor | null>(null);
3334

3435
React.useEffect(() => {
3536
const destroySystemThemeListener = useSystemTheme(systemTheme => {
@@ -55,6 +56,16 @@ const MonacoEditorLazy = React.lazy(() =>
5556
};
5657
}, []);
5758

59+
React.useEffect(() => {
60+
const onResize = () => {
61+
editorApiRef.current?.layout();
62+
};
63+
window.addEventListener('resize', onResize);
64+
return () => {
65+
window.removeEventListener('resize', onResize);
66+
};
67+
}, []);
68+
5869
return (
5970
<div
6071
style={{
@@ -79,6 +90,7 @@ const MonacoEditorLazy = React.lazy(() =>
7990
});
8091

8192
container.editorApi = editor;
93+
editorApiRef.current = editor;
8294
}
8395

8496
const model = monaco.editor.createModel(props.editor.input.text, props.editor.input.language);

0 commit comments

Comments
 (0)