From a827f8835bf92ac4a054df43432e4c09a67e9214 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Tue, 5 Nov 2024 11:59:07 +0000 Subject: [PATCH] Focus the editor after using the "Switch to editor" button (#21549) GitOrigin-RevId: f94c6d266ec9c2c3e4a30ea2c34c937817b48596 --- .../pdf-preview/components/switch-to-editor-button.tsx | 3 +++ .../features/source-editor/hooks/use-codemirror-scope.ts | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/services/web/frontend/js/features/pdf-preview/components/switch-to-editor-button.tsx b/services/web/frontend/js/features/pdf-preview/components/switch-to-editor-button.tsx index b3fd477373..dab10e8e80 100644 --- a/services/web/frontend/js/features/pdf-preview/components/switch-to-editor-button.tsx +++ b/services/web/frontend/js/features/pdf-preview/components/switch-to-editor-button.tsx @@ -20,6 +20,9 @@ function SwitchToEditorButton() { function handleClick() { setView('editor') + window.setTimeout(() => { + window.dispatchEvent(new Event('editor:focus')) + }) } return ( diff --git a/services/web/frontend/js/features/source-editor/hooks/use-codemirror-scope.ts b/services/web/frontend/js/features/source-editor/hooks/use-codemirror-scope.ts index 008f98f03e..46d15d4ab4 100644 --- a/services/web/frontend/js/features/source-editor/hooks/use-codemirror-scope.ts +++ b/services/web/frontend/js/features/source-editor/hooks/use-codemirror-scope.ts @@ -576,6 +576,13 @@ function useCodeMirrorScope(view: EditorView) { useEventListener('learnedWords:reset', handleResetLearnedWords) + useEventListener( + 'editor:focus', + useCallback(() => { + view.focus() + }, [view]) + ) + useEffect(() => { view.dispatch(reviewPanelToggled()) }, [reviewPanelOpen, miniReviewPanelVisible, view])