Skip to content

Commit

Permalink
fix: Check first code load on monaco editor
Browse files Browse the repository at this point in the history
  • Loading branch information
erdkse committed Aug 31, 2021
1 parent d259f1d commit 8a04908
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/components/molecules/Monaco/Monaco.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const Monaco = (props: {editorHeight: string}) => {
const [isDirty, setDirty] = useState(false);
const [hasWarnings, setWarnings] = useState(false);
const [isValid, setValid] = useState(true);
const [firstCodeLoadedOnEditor, setFirstCodeLoadedOnEditor] = useState(false);

const editorRef = useRef<monaco.editor.IStandaloneCodeEditor | null>(null);
const idsOfDecorationsRef = useRef<string[]>([]);
Expand Down Expand Up @@ -286,6 +287,10 @@ const Monaco = (props: {editorHeight: string}) => {
useEffect(() => {
clearCodeIntel();
applyCodeIntel();

if (!firstCodeLoadedOnEditor && code) {
setFirstCodeLoadedOnEditor(true);
}
return () => {
clearCodeIntel();
};
Expand Down Expand Up @@ -329,11 +334,11 @@ const Monaco = (props: {editorHeight: string}) => {
}, [selectedResourceId, resourceMap]);

useEffect(() => {
if (editor && code) {
if (editor) {
editor.revealLineNearTop(1);
editor.setSelection(new monaco.Selection(0, 0, 0, 0));
}
}, [editor, code]);
}, [editor, selectedResourceId, firstCodeLoadedOnEditor]);

return (
<>
Expand Down

0 comments on commit 8a04908

Please sign in to comment.