Focus the editor after using the "Switch to editor" button (#21549)

GitOrigin-RevId: f94c6d266ec9c2c3e4a30ea2c34c937817b48596
This commit is contained in:
Alf Eaton 2024-11-05 11:59:07 +00:00 committed by Copybot
parent 09ad023161
commit a827f8835b
2 changed files with 10 additions and 0 deletions

View file

@ -20,6 +20,9 @@ function SwitchToEditorButton() {
function handleClick() {
setView('editor')
window.setTimeout(() => {
window.dispatchEvent(new Event('editor:focus'))
})
}
return (

View file

@ -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])