11import { useMonaco } from "@monaco-editor/react" ;
2- import { lazy , Suspense , useCallback , useEffect , useMemo , MutableRefObject } from "react" ;
2+ import { lazy , Suspense , useCallback , useEffect , useMemo , useRef , MutableRefObject } from "react" ;
33import * as monaco from "monaco-editor" ;
44import useAppStore from "../store/store" ;
5+ import { shallow } from "zustand/shallow" ;
56import { useCodeSelection } from "../components/CodeSelectionMenu" ;
67import { registerAutocompletion } from "../ai-assistant/autocompletion" ;
78import { registerEditor , unregisterEditor } from "../utils/editorNavigation" ;
@@ -124,12 +125,13 @@ export default function ConcertoEditor({
124125} : ConcertoEditorProps ) {
125126 const { handleSelection, MenuComponent } = useCodeSelection ( "concerto" ) ;
126127 const monacoInstance = useMonaco ( ) ;
128+ const localEditorRef = useRef < monaco . editor . IStandaloneCodeEditor | null > ( null ) ;
127129 const { error, backgroundColor, aiConfig, showLineNumbers } = useAppStore ( ( state ) => ( {
128130 error : state . error ,
129131 backgroundColor : state . backgroundColor ,
130132 aiConfig : state . aiConfig ,
131133 showLineNumbers : state . showLineNumbers ,
132- } ) ) ;
134+ } ) , shallow ) ;
133135 const ctoErr = error ?. startsWith ( "c:" ) ? error : undefined ;
134136
135137 const themeName = useMemo (
@@ -165,6 +167,7 @@ export default function ConcertoEditor({
165167 } ) , [ aiConfig ?. enableInlineSuggestions , showLineNumbers ] ) ;
166168
167169 const handleEditorDidMount = ( editor : monaco . editor . IStandaloneCodeEditor ) => {
170+ localEditorRef . current = editor ;
168171 if ( editorRef ) {
169172 editorRef . current = editor ;
170173 }
@@ -190,7 +193,9 @@ export default function ConcertoEditor({
190193 useEffect ( ( ) => {
191194 if ( ! monacoInstance ) return ;
192195
193- const model = monacoInstance . editor . getModels ( ) ?. [ 0 ] ;
196+ const editor = localEditorRef . current ;
197+ if ( ! editor ) return ;
198+ const model = editor . getModel ( ) ;
194199 if ( ! model ) return ;
195200
196201 if ( ctoErr ) {
0 commit comments