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

Function initDiffEditor

src/web-ui/src/tools/editor/components/DiffEditor.tsx:183–379  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

181 let unbindEditTargets: (() => void) | null = null;
182
183 const initDiffEditor = async () => {
184 try {
185 await monacoInitManager.initialize();
186
187 const timestamp = Date.now();
188 const originalUri = monaco.Uri.parse(`inmemory://diff-original/${timestamp}/${filePath || 'untitled'}`);
189 const modifiedUri = monaco.Uri.parse(`inmemory://diff-modified/${timestamp}/${filePath || 'untitled'}`);
190
191 const existingOriginalModel = monaco.editor.getModel(originalUri);
192 const existingModifiedModel = monaco.editor.getModel(modifiedUri);
193
194 if (existingOriginalModel) {
195 existingOriginalModel.dispose();
196 }
197 if (existingModifiedModel) {
198 existingModifiedModel.dispose();
199 }
200
201 const existingOriginal = monaco.editor.getModel(originalUri);
202 if (existingOriginal) {
203 existingOriginal.dispose();
204 }
205
206 const existingModified = monaco.editor.getModel(modifiedUri);
207 if (existingModified) {
208 existingModified.dispose();
209 }
210
211 originalModel = monaco.editor.createModel(originalContentRuntimeRef.current, detectedLanguage, originalUri);
212 modifiedModel = monaco.editor.createModel(modifiedContentRuntimeRef.current, detectedLanguage, modifiedUri);
213
214 originalModelRef.current = originalModel;
215 modifiedModelRef.current = modifiedModel;
216
217 let themeId = BitFunDarkThemeMetadata.id;
218 try {
219 const { themeService } = await import('@/infrastructure/theme');
220 const currentTheme = themeService.getCurrentTheme();
221 if (currentTheme) {
222 themeId = currentTheme.monaco ? currentTheme.id : (currentTheme.type === 'dark' ? BitFunDarkThemeMetadata.id : 'vs');
223 setCurrentThemeId(themeId);
224 }
225 } catch (error) {
226 log.warn('Failed to get current theme, using default', error);
227 }
228
229 forceRegisterTheme(BitFunDarkThemeMetadata.id, BitFunDarkTheme);
230
231 const editorOptions: monaco.editor.IStandaloneDiffEditorConstructionOptions = {
232 renderSideBySide: renderSideBySide,
233 renderOverviewRuler: false,
234 renderIndicators: renderIndicatorsRuntimeRef.current,
235 renderMarginRevertIcon: true,
236 renderGutterMenu: true,
237
238 originalEditable: false,
239 readOnly: readOnly,
240

Callers 1

DiffEditorFunction · 0.85

Calls 15

forceRegisterThemeFunction · 0.90
createMonacoEditTargetFunction · 0.90
u1Function · 0.85
setErrorFunction · 0.85
getCurrentThemeMethod · 0.80
warnMethod · 0.80
getModifiedEditorMethod · 0.80
getOriginalEditorMethod · 0.80
bindTargetMethod · 0.80
layoutMethod · 0.80
getValueMethod · 0.80
getModelMethod · 0.65

Tested by

no test coverage detected