File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -50,11 +50,13 @@ export function FileTabs({
50
50
files,
51
51
activeFileIdx,
52
52
setActiveFileIdx,
53
- closeFile
53
+ focusEditor,
54
+ closeFile,
54
55
} : {
55
56
files : EditorItem [ ] ;
56
57
activeFileIdx : number ;
57
58
setActiveFileIdx : React . Dispatch < React . SetStateAction < number > > ;
59
+ focusEditor : ( ) => void ;
58
60
closeFile : ( e : React . SyntheticEvent , index : number ) => void ;
59
61
} ) {
60
62
return (
@@ -74,7 +76,10 @@ export function FileTabs({
74
76
< button
75
77
className = "editor-switch"
76
78
aria-label = { `Switch to ${ f . name } ` }
77
- onClick = { ( ) => setActiveFileIdx ( index ) }
79
+ onClick = { ( ) => {
80
+ setActiveFileIdx ( index ) ;
81
+ setTimeout ( focusEditor , 0 ) ;
82
+ } }
78
83
>
79
84
</ button >
80
85
< div
@@ -342,6 +347,12 @@ export function Editor({
342
347
} ;
343
348
} , [ saveFile , editorView , activeFile ] ) ;
344
349
350
+ const focusEditor = React . useCallback ( ( ) => {
351
+ if ( editorView ) {
352
+ editorView . focus ( ) ;
353
+ }
354
+ } , [ editorView ] ) ;
355
+
345
356
React . useEffect ( ( ) => {
346
357
if ( ! editorRef . current ) {
347
358
return ;
@@ -514,6 +525,7 @@ export function Editor({
514
525
activeFileIdx = { activeFileIdx }
515
526
setActiveFileIdx = { setActiveFileIdx }
516
527
closeFile = { closeFile }
528
+ focusEditor = { focusEditor }
517
529
/>
518
530
</ div >
519
531
< div
You can’t perform that action at this time.
0 commit comments