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() { function handleClick() {
setView('editor') setView('editor')
window.setTimeout(() => {
window.dispatchEvent(new Event('editor:focus'))
})
} }
return ( return (

View file

@ -576,6 +576,13 @@ function useCodeMirrorScope(view: EditorView) {
useEventListener('learnedWords:reset', handleResetLearnedWords) useEventListener('learnedWords:reset', handleResetLearnedWords)
useEventListener(
'editor:focus',
useCallback(() => {
view.focus()
}, [view])
)
useEffect(() => { useEffect(() => {
view.dispatch(reviewPanelToggled()) view.dispatch(reviewPanelToggled())
}, [reviewPanelOpen, miniReviewPanelVisible, view]) }, [reviewPanelOpen, miniReviewPanelVisible, view])