()
| 182 | }); |
| 183 | |
| 184 | const initEditor = async () => { |
| 185 | try { |
| 186 | await monacoInitManager.initialize(); |
| 187 | |
| 188 | if (isUnmountedRef.current) return; |
| 189 | |
| 190 | themeManager.initialize(); |
| 191 | |
| 192 | const model = monacoModelManager.getOrCreateModel( |
| 193 | currentFilePath, |
| 194 | languageRef.current, |
| 195 | initialContentRef.current, |
| 196 | workspacePathRef.current |
| 197 | ); |
| 198 | modelRef.current = model; |
| 199 | |
| 200 | const overrides: EditorOptionsOverrides = { |
| 201 | readOnly: readOnlyRef.current, |
| 202 | lineNumbers: showLineNumbersRef.current, |
| 203 | minimap: showMinimapRef.current, |
| 204 | theme: themeRef.current, |
| 205 | }; |
| 206 | |
| 207 | const editorOptions = buildEditorOptions({ |
| 208 | config: configRef.current, |
| 209 | preset: presetRef.current, |
| 210 | overrides, |
| 211 | }); |
| 212 | |
| 213 | const editor = monaco.editor.create(container, { |
| 214 | ...editorOptions, |
| 215 | model, |
| 216 | }); |
| 217 | editorRef.current = editor; |
| 218 | const editTarget = createMonacoEditTarget(editor); |
| 219 | const unbindEditTarget = activeEditTargetService.bindTarget(editTarget); |
| 220 | const focusDisposable = editor.onDidFocusEditorText(() => { |
| 221 | activeEditTargetService.setActiveTarget(editTarget.id); |
| 222 | }); |
| 223 | const blurDisposable = editor.onDidBlurEditorText(() => { |
| 224 | window.setTimeout(() => { |
| 225 | if (editor.hasTextFocus()) { |
| 226 | return; |
| 227 | } |
| 228 | |
| 229 | activeEditTargetService.clearActiveTarget(editTarget.id); |
| 230 | }, 0); |
| 231 | }); |
| 232 | macosEditorBindingCleanupRef.current = () => { |
| 233 | focusDisposable.dispose(); |
| 234 | blurDisposable.dispose(); |
| 235 | unbindEditTarget(); |
| 236 | }; |
| 237 | |
| 238 | registerEventListeners(editor, model); |
| 239 | |
| 240 | editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, () => { |
| 241 | const content = model.getValue(); |
no test coverage detected