MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / applyFileToEditor

Function applyFileToEditor

src/lib/editorManager.js:1472–1600  ·  view source on GitHub ↗
(file, options = {})

Source from the content-addressed store, hash-verified

1470
1471 // Helper: apply a file's content and language to the editor view
1472 function applyFileToEditor(file, options = {}) {
1473 if (!file || file.type !== "editor") return;
1474 const { forceRecreate = false } = options;
1475 const extensionSignature = getEditorExtensionSignature(file);
1476 const languageSignature = getFileLanguageSignature(
1477 file,
1478 extensionSignature,
1479 );
1480
1481 if (!forceRecreate && isReusableEditorState(file, extensionSignature)) {
1482 const reusedState = getRawEditorState(file.session);
1483 editor.setState(reusedState);
1484 applyCurrentEditorOptions(file);
1485
1486 if (shouldApplyLanguage(file, reusedState, languageSignature)) {
1487 const ext = resolveLanguageExtension(
1488 file,
1489 languageSignature,
1490 "reused-language-reconfigure",
1491 );
1492 if (file.__cmLanguageReady) {
1493 dispatchLanguageExtension(
1494 file,
1495 languageSignature,
1496 ext,
1497 "reused-language-reconfigure",
1498 );
1499 }
1500 }
1501
1502 restoreFileScrollPosition(file);
1503 scheduleLspForFile(file);
1504 return;
1505 }
1506
1507 const syntax = getEmmetSyntaxForFile(file);
1508 const baseExtensions = createMainEditorExtensions({
1509 // Emmet needs to precede default keymaps so tracker Tab wins over indent
1510 emmetExtensions: createEmmetExtensionSet({ syntax }),
1511 baseExtensions: createConfiguredBaseExtensions(),
1512 commandKeymapExtension: getCommandKeymapExtension(),
1513 // keep compartment in the state to allow dynamic theme changes later
1514 themeExtension: themeCompartment.of(getConfiguredThemeExtension()),
1515 pointerCursorVisibilityExtension,
1516 shiftClickSelectionExtension,
1517 touchSelectionUpdateExtension,
1518 searchExtension: search(),
1519 // Keep dynamic compartments across state swaps
1520 optionExtensions: getBaseExtensionsFromOptions(),
1521 });
1522 const exts = [...baseExtensions];
1523 maybeAttachEmmetCompletions(exts, syntax);
1524 try {
1525 const initialLang = resolveLanguageExtension(
1526 file,
1527 languageSignature,
1528 "async-language-reconfigure",
1529 );

Callers 4

EditorManagerFunction · 0.85
switchFileFunction · 0.85
reapplyActiveFileFunction · 0.85

Calls 15

searchFunction · 0.90
restoreSelectionFunction · 0.90
getAllFoldsFunction · 0.90
restoreFoldsFunction · 0.90
getFileLanguageSignatureFunction · 0.85
isReusableEditorStateFunction · 0.85
getRawEditorStateFunction · 0.85
shouldApplyLanguageFunction · 0.85
resolveLanguageExtensionFunction · 0.85

Tested by

no test coverage detected