Skip to content

fix: highlighting issue happening due to state reuse#2180

Merged
bajrangCoder merged 2 commits into
Acode-Foundation:mainfrom
bajrangCoder:fix/highlighting-issue
Jun 10, 2026
Merged

fix: highlighting issue happening due to state reuse#2180
bajrangCoder merged 2 commits into
Acode-Foundation:mainfrom
bajrangCoder:fix/highlighting-issue

Conversation

@bajrangCoder

Copy link
Copy Markdown
Member

No description provided.

@greptile-apps

greptile-apps Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR addresses a syntax-highlighting regression caused by CodeMirror editor state being reused across file switches without re-applying the language compartment. It adds explicit language-extension re-configuration in the reusable-state path of applyFileToEditor, and attempts to force a re-apply after a file finishes loading while it is the active file.

  • editorManager.js: When isReusableEditorState is true, the existing setState call is now followed by an explicit languageCompartment.reconfigure dispatch — async loaders are guarded by file-id and signature checks before dispatching.
  • editorFile.js: After a file load completes and the file is already active, switchFile(this.id) is called to re-apply the editor state; however, switchFile contains an early-return guard (if (activeFileId === id) return) that always fires in this branch, making the call a no-op.

Confidence Score: 3/5

The editorManager.js language-compartment fix is directionally correct but the editorFile.js change is a no-op, so the post-load re-apply path it was meant to cover silently does nothing.

The core editorManager.js change correctly re-applies language extensions when state is reused on file switch, which should resolve highlighting in the most common case. However, the editorFile.js change — which was meant to handle the active-file-reload scenario — calls switchFile with the already-active file ID and always hits the early-return guard, leaving the editor potentially stale after a file finishes loading. The synchronous branch in the new applyFileToEditor code also skips reconfiguring the language compartment when the loader returns nothing, which can leave a previous file's language extensions active.

Both changed files need attention: editorFile.js for the ineffective switchFile call, and editorManager.js for the synchronous-branch gap in the language compartment reset.

Important Files Changed

Filename Overview
src/lib/editorFile.js Calls switchFile(this.id) to force a re-apply of the loaded file, but switchFile has an early-return guard that makes the call a no-op when the file is already active — the intended fix never executes.
src/lib/editorManager.js Adds language-extension re-application inside the reusable-state path of applyFileToEditor; the async staleness guard is sound, but the synchronous branch silently skips reconfiguring the compartment when the loader returns falsy/empty, potentially leaving a stale language from the previous file.

Sequence Diagram

sequenceDiagram
    participant EF as EditorFile.load()
    participant EM as editorManager
    participant AFE as applyFileToEditor()
    participant CM as CodeMirror editor

    EF->>EF: "session = EditorState.create({doc})"
    EF->>EF: "__cmSessionReady = false"
    EF->>EF: markLoaded()
    EF->>EM: switchFile(this.id)
    EM-->>EF: early return (file already active — no-op)

    Note over CM: Editor still shows old/stale state

    EM->>AFE: switchFile called from tab click
    AFE->>AFE: isReusableEditorState?
    alt state reusable
        AFE->>CM: editor.setState(session)
        AFE->>CM: languageCompartment.reconfigure(langExt) NEW
    else state not reusable
        AFE->>CM: editor.setState(new full state)
    end
Loading

Reviews (1): Last reviewed commit: "fix: highlighting issue happening due to..." | Re-trigger Greptile

Comment thread src/lib/editorFile.js Outdated
Comment thread src/lib/editorManager.js
@bajrangCoder bajrangCoder merged commit 74d0efa into Acode-Foundation:main Jun 10, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in The Code Board - Acode Jun 10, 2026
@bajrangCoder bajrangCoder deleted the fix/highlighting-issue branch June 10, 2026 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant