@@ -141,6 +141,7 @@ export const useEditors = ({ wsRef, isConnected, diffEnabled, onFileClosed }: Us
141141 const activeEditorPaneIdRef = useRef < string > ( DEFAULT_EDITOR_PANE_ID ) ;
142142 const [ paneActiveFileIds , setPaneActiveFileIds ] = useState < Record < string , string | null > > ( ( ) => persistedPaneActiveFileIds ) ;
143143 const paneActiveFileIdsRef = useRef < Record < string , string | null > > ( persistedPaneActiveFileIds ) ;
144+ const registeredPaneIdsRef = useRef < Set < string > > ( new Set ( [ DEFAULT_EDITOR_PANE_ID ] ) ) ;
144145 const activeFileId = paneActiveFileIds [ activeEditorPaneId ] ?? null ;
145146 const activeFileIdRef = useRef < string | null > ( persistedEditorState . activeFileId ) ;
146147
@@ -166,7 +167,7 @@ export const useEditors = ({ wsRef, isConnected, diffEnabled, onFileClosed }: Us
166167
167168 const activeFile = files . find ( ( f ) => f . id === activeFileId ) ;
168169 const hasVisibleEditorPane = useCallback ( ( ) => (
169- Object . keys ( paneActiveFileIdsRef . current ) . some ( ( id ) => id !== DEFAULT_EDITOR_PANE_ID )
170+ Array . from ( registeredPaneIdsRef . current ) . some ( ( id ) => id !== DEFAULT_EDITOR_PANE_ID )
170171 ) , [ ] ) ;
171172
172173 // Choose the editor pane we should target for an open/select action.
@@ -177,10 +178,12 @@ export const useEditors = ({ wsRef, isConnected, diffEnabled, onFileClosed }: Us
177178 // 4) the only visible editor pane
178179 // 5) the default editor pane as a safe fallback
179180 const resolveTargetPaneId = useCallback ( ( paneId ?: string , fileId ?: string ) => {
180- const paneEntries = Object . entries ( paneActiveFileIdsRef . current ) ;
181+ const registeredPaneIds = registeredPaneIdsRef . current ;
182+ const paneEntries = Object . entries ( paneActiveFileIdsRef . current )
183+ . filter ( ( [ id ] ) => registeredPaneIds . has ( id ) ) ;
181184 const paneIds = paneEntries . map ( ( [ id ] ) => id ) ;
182185 const visiblePaneIds = paneIds . filter ( ( id ) => id !== DEFAULT_EDITOR_PANE_ID ) ;
183- const isKnownPane = ( id : string ) => Object . hasOwn ( paneActiveFileIdsRef . current , id ) ;
186+ const isKnownPane = ( id : string ) => registeredPaneIds . has ( id ) ;
184187
185188 if ( paneId ) {
186189 return paneId ;
@@ -276,6 +279,7 @@ export const useEditors = ({ wsRef, isConnected, diffEnabled, onFileClosed }: Us
276279 } , [ hasVisibleEditorPane , resolveTargetPaneId ] ) ;
277280
278281 const registerEditorPane = useCallback ( ( paneId : string ) => {
282+ registeredPaneIdsRef . current . add ( paneId ) ;
279283 setPaneActiveFileIds ( ( prev ) => {
280284 if ( Object . hasOwn ( prev , paneId ) ) return prev ;
281285 return {
@@ -306,6 +310,7 @@ export const useEditors = ({ wsRef, isConnected, diffEnabled, onFileClosed }: Us
306310 } , [ pendingExistingOpenRequest , setActiveFileId ] ) ;
307311
308312 const unregisterEditorPane = useCallback ( ( paneId : string ) => {
313+ registeredPaneIdsRef . current . delete ( paneId ) ;
309314 setReferencesPeekByPane ( ( prev ) => {
310315 if ( ! Object . hasOwn ( prev , paneId ) ) return prev ;
311316 const next = { ...prev } ;
@@ -592,7 +597,6 @@ export const useEditors = ({ wsRef, isConnected, diffEnabled, onFileClosed }: Us
592597
593598 const existingFile = filesRef . current . find ( ( file ) => file . id === path ) ;
594599 const targetPaneId = resolveTargetPaneId ( paneId , existingFile ?. id ) ;
595- console . log ( '[openFile]' , { path, line, column } ) ;
596600
597601 if ( existingFile ) {
598602 const editor = editorRefs . current . get ( existingFile . id ) ;
@@ -903,14 +907,15 @@ export const useEditors = ({ wsRef, isConnected, diffEnabled, onFileClosed }: Us
903907 for ( const file of filesRef . current ) {
904908 if ( ! editorStatesRef . current . has ( file . id ) ) {
905909 const content = savedFileContentsRef . current . get ( file . id ) ;
906- if ( content === undefined ) continue ;
910+ if ( content === undefined ) {
911+ continue ;
912+ }
907913
908914 const pendingPosition = pendingPositions . current . get ( file . id ) ;
909915 const pendingDiagnostics = diagnosticsRef . current . get ( file . id ) ;
910916 const errors = pendingDiagnostics
911917 ? pendingDiagnostics . map ( ( d ) => ( { line : d . range . start . line , message : d . message } ) )
912918 : undefined ;
913-
914919 const editor = await createEditor ( content , file . language , file . id , pendingPosition , errors , file . history ) ;
915920 newEditorStates . set ( file . id , editor ) ;
916921 savedFileContentsRef . current . set ( file . id , content ) ;
0 commit comments