()
| 633 | let model: monaco.editor.ITextModel | null = null; |
| 634 | |
| 635 | const initEditor = async () => { |
| 636 | try { |
| 637 | if (!containerRef.current) { |
| 638 | log.error('Container ref is null'); |
| 639 | return; |
| 640 | } |
| 641 | |
| 642 | let createFontSize = 14; |
| 643 | let createFontFamily = editorConfigRuntimeRef.current.font_family || "'Fira Code', 'Noto Sans SC', Consolas, 'Courier New', monospace"; |
| 644 | let createFontWeight = editorConfigRuntimeRef.current.font_weight || 'normal'; |
| 645 | let createLineHeight = 0; |
| 646 | const applyFontConfig = (c: Partial<EditorConfigType>) => { |
| 647 | createFontSize = c.font_size ?? 14; |
| 648 | createFontFamily = c.font_family || createFontFamily; |
| 649 | createFontWeight = c.font_weight || createFontWeight; |
| 650 | createLineHeight = c.line_height ? Math.round(createFontSize * c.line_height) : 0; |
| 651 | }; |
| 652 | try { |
| 653 | const preloadConfig = await configManager.getConfig<EditorConfigType>('editor'); |
| 654 | if (preloadConfig) applyFontConfig(preloadConfig); |
| 655 | else if (latestEditorConfigRef.current) applyFontConfig(latestEditorConfigRef.current); |
| 656 | } catch (_) {} |
| 657 | |
| 658 | await monacoInitManager.initialize(); |
| 659 | |
| 660 | model = monacoModelManager.getOrCreateModel( |
| 661 | filePath, |
| 662 | detectedLanguage, |
| 663 | contentRef.current || '', |
| 664 | workspacePathRuntimeRef.current |
| 665 | ); |
| 666 | |
| 667 | modelRef.current = model; |
| 668 | const modelContent = model.getValue(); |
| 669 | const initialLargeFileMode = detectLargeFileMode(modelContent); |
| 670 | largeFileModeRef.current = initialLargeFileMode; |
| 671 | setLargeFileMode(initialLargeFileMode); |
| 672 | |
| 673 | const modelMetadata = monacoModelManager.getModelMetadata(filePath); |
| 674 | if (modelMetadata) { |
| 675 | const isDirty = modelMetadata.isDirty; |
| 676 | |
| 677 | setHasChanges(isDirty); |
| 678 | hasChangesRef.current = isDirty; |
| 679 | savedVersionIdRef.current = modelMetadata.savedVersionId; |
| 680 | originalContentRef.current = modelMetadata.originalContent; |
| 681 | |
| 682 | if (isDirty && onContentChangeRef.current) { |
| 683 | onContentChangeRef.current(modelContent, true); |
| 684 | } |
| 685 | } else { |
| 686 | savedVersionIdRef.current = model.getAlternativeVersionId(); |
| 687 | } |
| 688 | |
| 689 | if (modelContent && modelContent !== contentRef.current) { |
| 690 | setContent(modelContent); |
| 691 | if (!modelMetadata) { |
| 692 | originalContentRef.current = modelContent; |
no test coverage detected