From 0b20796b9257f110868ddb764e3d8426c48dd116 Mon Sep 17 00:00:00 2001 From: Huy Date: Sat, 25 Sep 2021 14:26:58 +0700 Subject: [PATCH 1/3] Feat: Focus editor on open file --- src/app/utils/open.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/utils/open.ts b/src/app/utils/open.ts index dda1dd1..e756672 100644 --- a/src/app/utils/open.ts +++ b/src/app/utils/open.ts @@ -41,6 +41,7 @@ const updateEditor = async (params: Params): Promise => { const text = fileHandle === null ? "" : await fileSystem.safeRead(fileHandle); const model = monaco.editor.createModel(text, "markdown"); editor.setModel(model); + setTimeout(() => editor.focus(), 0); }; /** From 45324a6162e7609f481af27360a8fa95d6285255 Mon Sep 17 00:00:00 2001 From: Huy Date: Sat, 25 Sep 2021 17:38:05 +0700 Subject: [PATCH 2/3] Chore: Move focus editor to a separate function --- src/app/utils/open.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/app/utils/open.ts b/src/app/utils/open.ts index e756672..c2e4c5f 100644 --- a/src/app/utils/open.ts +++ b/src/app/utils/open.ts @@ -41,6 +41,10 @@ const updateEditor = async (params: Params): Promise => { const text = fileHandle === null ? "" : await fileSystem.safeRead(fileHandle); const model = monaco.editor.createModel(text, "markdown"); editor.setModel(model); +}; + +const focusEditor = (editor: Editor | null): void => { + if (editor === null) throw ERRORS.editorNull; setTimeout(() => editor.focus(), 0); }; @@ -61,4 +65,7 @@ export const openFile = async (params: Params): Promise => { // Update editor await updateEditor(params); + + // Update focus to editor + focusEditor(params.editor); }; From 6f57d2e08ae4b5644312450abf3231d33439634c Mon Sep 17 00:00:00 2001 From: Thien Do Date: Sun, 26 Sep 2021 11:45:21 +0700 Subject: [PATCH 3/3] Refactor: Simplify app open --- src/app/utils/open.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/app/utils/open.ts b/src/app/utils/open.ts index c2e4c5f..e756672 100644 --- a/src/app/utils/open.ts +++ b/src/app/utils/open.ts @@ -41,10 +41,6 @@ const updateEditor = async (params: Params): Promise => { const text = fileHandle === null ? "" : await fileSystem.safeRead(fileHandle); const model = monaco.editor.createModel(text, "markdown"); editor.setModel(model); -}; - -const focusEditor = (editor: Editor | null): void => { - if (editor === null) throw ERRORS.editorNull; setTimeout(() => editor.focus(), 0); }; @@ -65,7 +61,4 @@ export const openFile = async (params: Params): Promise => { // Update editor await updateEditor(params); - - // Update focus to editor - focusEditor(params.editor); };