MCPcopy Create free account
hub / github.com/GCWing/BitFun / initEditor

Function initEditor

src/web-ui/src/tools/editor/components/CodeEditor.tsx:635–1033  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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;

Callers 1

CodeEditorFunction · 0.70

Calls 15

forceRegisterThemeFunction · 0.90
createMonacoEditTargetFunction · 0.90
applyFontConfigFunction · 0.85
applyOptionsFromConfigFunction · 0.85
setSelectionFunction · 0.85
updateCursorPositionFunction · 0.85
setErrorFunction · 0.85
getOrCreateModelMethod · 0.80
getValueMethod · 0.80
getModelMetadataMethod · 0.80
getCurrentThemeMethod · 0.80
warnMethod · 0.80

Tested by

no test coverage detected