Skip to content

Commit

Permalink
implement preventCreation flag
Browse files Browse the repository at this point in the history
  • Loading branch information
suren-atoyan committed Sep 24, 2022
1 parent 1ef4d96 commit 6f0ce34
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/Editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function Editor({
const subscriptionRef = useRef(null);
const valueRef = useRef(value);
const previousPath = usePrevious(path);
const preventCreation = useRef(false);

useMount(() => {
const cancelable = loader.init();
Expand Down Expand Up @@ -109,27 +110,30 @@ function Editor({
}, [theme], isEditorReady);

const createEditor = useCallback(() => {
beforeMountRef.current(monacoRef.current);
const autoCreatedModelPath = path || defaultPath;
if (!preventCreation.current) {
beforeMountRef.current(monacoRef.current);
const autoCreatedModelPath = path || defaultPath;

const defaultModel = getOrCreateModel(
monacoRef.current,
value || defaultValue,
defaultLanguage || language,
autoCreatedModelPath,
);
const defaultModel = getOrCreateModel(
monacoRef.current,
value || defaultValue,
defaultLanguage || language,
autoCreatedModelPath,
);

editorRef.current = monacoRef.current.editor.create(containerRef.current, {
model: defaultModel,
automaticLayout: true,
...options,
}, overrideServices);
editorRef.current = monacoRef.current.editor.create(containerRef.current, {
model: defaultModel,
automaticLayout: true,
...options,
}, overrideServices);

saveViewState && editorRef.current.restoreViewState(viewStates.get(autoCreatedModelPath));
saveViewState && editorRef.current.restoreViewState(viewStates.get(autoCreatedModelPath));

monacoRef.current.editor.setTheme(theme);
monacoRef.current.editor.setTheme(theme);

setIsEditorReady(true);
setIsEditorReady(true);
preventCreation.current = true;
}
}, [
defaultValue,
defaultLanguage,
Expand Down

0 comments on commit 6f0ce34

Please sign in to comment.