Skip to content

fix(editor): use versioned dirty state and debounced cache writes, also avoid full string conversion of editor buffer #2145

Open
bajrangCoder wants to merge 15 commits into
Acode-Foundation:mainfrom
bajrangCoder:editor-versioned-dirty-cache
Open

fix(editor): use versioned dirty state and debounced cache writes, also avoid full string conversion of editor buffer #2145
bajrangCoder wants to merge 15 commits into
Acode-Foundation:mainfrom
bajrangCoder:editor-versioned-dirty-cache

Conversation

@bajrangCoder
Copy link
Copy Markdown
Member

@bajrangCoder bajrangCoder commented Jun 2, 2026

  • track editor dirty state with version metadata and CodeMirror Text equality
  • debounce cache snapshots and flush pending writes on switch/pause/save
  • avoid full doc string conversion for tab switches and equality checks
  • use mtime metadata for external file change detection
  • disable native webview selection menu in terminal
  • add setting to change cursor width and set default to 2 instead of 1
  • avoid rebuilding state on every tab switch
  • improve color view and indent guide extension
  • Fixed the terminal touch-selection handle oscillation

- track editor dirty state with version metadata and CodeMirror Text equality
- debounce cache snapshots and flush pending writes on switch/pause/save
- avoid full doc string conversion for tab switches and equality checks
- use mtime metadata for external file change detection
@bajrangCoder bajrangCoder added the CI: RUN ON-DEMAND PREVIEW RELEASES Triggers an on-demand preview build for this pull request via CI workflow. label Jun 2, 2026
@github-actions github-actions Bot removed the CI: RUN ON-DEMAND PREVIEW RELEASES Triggers an on-demand preview build for this pull request via CI workflow. label Jun 2, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment was marked as outdated.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Jun 2, 2026

Greptile Summary

This PR introduces versioned dirty-state tracking (docVersion/savedVersion/cacheVersion) and CodeMirror Text equality checks to avoid full string conversions, debounces cache writes with explicit flush points on tab switch and app pause, and adds mtime metadata for external-change detection. Several smaller improvements are bundled: cursor-width setting, terminal native-selection suppression, and performance refactors for colorView and indentGuides.

  • editorFile.js — new markLoaded/markSaved/markEdited/markDiskChanged helpers drive dirty state; writeToCache now snapshots docVersion before the await, fixing the stale-cacheVersion race from previous review threads.
  • checkFiles.js — adds mtime fast-path and disk-conflict detection, but scheduleCacheWrite(0) after a disk reload is silently skipped by the cacheVersion === docVersion guard that markLoaded just set, leaving the stale cache file on disk.
  • saveFile.js — snapshots savedDoc/savedVersion before the write and calls markSaved with a post-write stat() mtime; wraps formatOnSave in try/finally to always restore markChanged.

Confidence Score: 3/5

A cache-staleness regression in checkFiles means a user who accepts reload-from-disk will silently see the old content again after the next restart.

The scheduleCacheWrite(0) call after a confirmed reload is defeated by the cacheVersion===docVersion guard that markLoaded just set, and the mtime shortcut then prevents re-detection on subsequent checkFiles runs. This is a data-visibility regression on the changed code path that needs a targeted fix before the change ships.

src/lib/checkFiles.js and src/lib/editorFile.js (markLoaded / scheduleCacheWrite interaction)

Important Files Changed

Filename Overview
src/lib/editorFile.js Core of the PR: adds versioned dirty-state tracking, debounced/flushed cache writes, and markLoaded/markSaved/markEdited/markDiskChanged helpers. The writeToCache version-snapshot fix addresses thread-flagged races, but the scheduleCacheWrite guard silently skips the explicit flush in checkFiles.
src/lib/checkFiles.js Adds mtime fast-path and disk-conflict detection. The scheduleCacheWrite(0) call after reload is a no-op due to cacheVersion===docVersion guard set by markLoaded, leaving stale cache on disk.
src/lib/saveFile.js Snapshots savedDoc/savedVersion before the write; formatOnSave now has try/finally to restore markChanged. Async formatters may still bump docVersion past savedVersion after markSaved completes.
src/lib/editorManager.js Adds cursorWidth compartment, session-reuse optimisation, flushCacheWrites(), and moves markEdited() into the dispatch listener. Changes look correct.
src/cm/colorView.ts Rewrites ColorViewPlugin to dirty-range tracking with setTimeout batching; adds scan limits and colorRaw to eq(). Solid.
src/components/terminal/terminal.js Adds disableNativeSelectionMenu() with correct cleanup on destroy(). Called twice but second call correctly replaces first handler.

Reviews (7): Last reviewed commit: "Fixed the terminal touch-selection handl..." | Re-trigger Greptile

Comment thread src/lib/editorFile.js
Comment thread src/lib/editorFile.js
@bajrangCoder

This comment was marked as outdated.

Comment thread src/lib/saveFile.js Outdated
@bajrangCoder

This comment was marked as outdated.

@bajrangCoder

This comment was marked as outdated.

Comment thread src/lib/checkFiles.js
@bajrangCoder

This comment was marked as outdated.

Comment thread src/lib/saveFile.js
@bajrangCoder

This comment was marked as outdated.

@bajrangCoder bajrangCoder added this to the Acode v1.12.0(970) milestone Jun 3, 2026
@bajrangCoder

This comment was marked as outdated.

@bajrangCoder bajrangCoder requested a review from deadlyjack June 4, 2026 16:28
Comment thread src/lib/checkFiles.js Outdated
@bajrangCoder bajrangCoder added the CI: RUN ON-DEMAND PREVIEW RELEASES Triggers an on-demand preview build for this pull request via CI workflow. label Jun 5, 2026
@github-actions github-actions Bot removed the CI: RUN ON-DEMAND PREVIEW RELEASES Triggers an on-demand preview build for this pull request via CI workflow. label Jun 5, 2026
@github-actions

This comment has been minimized.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 5, 2026

Preview Release for this, has been built.

Click here to view that github actions build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant