1- import { AnycodeEditorReact } from 'anycode-react' ;
1+ import { useEffect , useState } from 'react' ;
2+ import { AnycodeEditor , AnycodeEditorReact } from 'anycode-react' ;
23import type { ReferencesPeekState } from '../../types' ;
34import { ReferencesPeek } from './ReferencesPeek' ;
45
56type EditorPanelProps = {
67 panelKey : string ;
78 editors : {
89 files : Array < { id : string } > ;
9- editorStates : ReadonlyMap < string , unknown > ;
10+ editorStates : ReadonlyMap < string , AnycodeEditor > ;
1011 getActiveFileIdForPane : ( paneId : string ) => string | null ;
1112 setActiveEditorPaneId : ( paneId : string ) => void ;
1213 getReferencesPeekForPane : ( paneId : string ) => ReferencesPeekState | null ;
@@ -22,17 +23,28 @@ export const EditorPanel = ({ panelKey, editors }: EditorPanelProps) => {
2223 const paneFile = paneFileId ? editors . files . find ( ( file ) => file . id === paneFileId ) : null ;
2324 const editorState = paneFile ? editors . editorStates . get ( paneFile . id ) : null ;
2425 const referencesPeek = editors . getReferencesPeekForPane ( panelKey ) ;
26+ const [ lastReadyEditor , setLastReadyEditor ] = useState < { id : string ; state : AnycodeEditor } | null > ( null ) ;
27+
28+ useEffect ( ( ) => {
29+ if ( paneFile && editorState ) {
30+ setLastReadyEditor ( { id : paneFile . id , state : editorState } ) ;
31+ }
32+ } , [ paneFile , editorState ] ) ;
33+
34+ const displayedEditor = paneFile && editorState
35+ ? { id : paneFile . id , state : editorState }
36+ : lastReadyEditor ;
2537
2638 return (
2739 < div
2840 className = "editor-container"
2941 onMouseDown = { ( ) => editors . setActiveEditorPaneId ( panelKey ) }
3042 >
31- { paneFile && editorState ? (
43+ { displayedEditor ? (
3244 < AnycodeEditorReact
33- key = { `${ panelKey } :${ paneFile . id } ` }
34- id = { paneFile . id }
35- editorState = { editorState as never }
45+ key = { `${ panelKey } :${ displayedEditor . id } ` }
46+ id = { displayedEditor . id }
47+ editorState = { displayedEditor . state }
3648 />
3749 ) : (
3850 < div className = "no-editor" > </ div >
0 commit comments