Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/lib/editorFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1625,9 +1625,11 @@ export default class EditorFile {
this.loaded = true;
this.loading = false;

const { activeFile, emit } = editorManager;
const { activeFile, emit, switchFile } = editorManager;
if (activeFile?.id === this.id) {
this.setReadOnly(editable === false);
// Re-apply file to editor with loaded content and language extensions
switchFile?.(this.id);
Comment thread
bajrangCoder marked this conversation as resolved.
Outdated
emit("file-loaded", this);
} else if (editable !== undefined) {
this.readOnly = !editable;
Expand Down
53 changes: 53 additions & 0 deletions src/lib/editorManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,59 @@ async function EditorManager($header, $body) {
if (!forceRecreate && isReusableEditorState(file, extensionSignature)) {
editor.setState(getRawEditorState(file.session));
applyCurrentEditorOptions(file);

// Ensure language extensions are properly applied even when reusing state
const langExtFn = file.currentLanguageExtension;
if (typeof langExtFn === "function") {
let result;
try {
result = langExtFn();
} catch (_) {
result = [];
}
// If the loader returns a Promise, reconfigure when it resolves
if (result && typeof result.then === "function") {
const fileId = file.id;
const expectedSignature = extensionSignature;
result
.then((ext) => {
if (
manager.activeFile?.id !== fileId ||
file.__cmExtensionSignature !== expectedSignature
) {
return;
}
try {
editor.dispatch({
effects: languageCompartment.reconfigure(ext || []),
});
} catch (error) {
warnRecoverable(
"Failed to apply language extensions for reused state.",
error,
"reused-language-reconfigure",
);
}
})
.catch(() => {
// ignore load errors; remain in plain text
});
} else if (result && result.length) {
// Synchronous language extensions available
try {
editor.dispatch({
effects: languageCompartment.reconfigure(result),
});
} catch (error) {
warnRecoverable(
"Failed to apply language extensions for reused state.",
error,
"reused-language-reconfigure",
);
}
}
Comment thread
bajrangCoder marked this conversation as resolved.
}

if (
typeof file.lastScrollTop === "number" ||
typeof file.lastScrollLeft === "number"
Expand Down