fix(editor): use versioned dirty state and debounced cache writes, also avoid full string conversion of editor buffer #2145
Conversation
- 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
This comment has been minimized.
This comment has been minimized.
|
Preview Release for this, has been built. |
Greptile SummaryThis PR overhauls the editor's dirty-state tracking by introducing versioned state (
Confidence Score: 3/5Four of the five data integrity regressions from prior rounds are properly resolved, but the cache-write path after a confirmed external-file reload still does not execute as intended — the version guard short-circuits the write, leaving stale cache content on disk that will be silently shown on the next restart. The remaining gap is in checkFiles.js: after markLoaded resets cacheVersion and docVersion both to zero, the scheduleCacheWrite(0) call hits the guard cacheVersion === docVersion and returns without writing. The mtime optimisation then prevents the safety-net content comparison from catching the stale cache on startup. src/lib/checkFiles.js and src/lib/editorFile.js — the interaction between markLoaded resetting cacheVersion to match docVersion and the scheduleCacheWrite guard that relies on that equality to skip writes. Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant DocSyncListener
participant EditorFile
participant CacheTimer
participant SaveFile
participant Disk
User->>DocSyncListener: keypress (docChanged)
DocSyncListener->>EditorFile: "markEdited() -> docVersion++"
DocSyncListener->>CacheTimer: checkTimeout (debounce)
CacheTimer->>EditorFile: scheduleCacheWrite(1500ms)
EditorFile->>CacheTimer: debounce timer set
User->>SaveFile: save command
SaveFile->>EditorFile: flushCacheWrite() [cancel timer, await write]
EditorFile->>Disk: writeToCache(docVersion snapshot)
Disk-->>EditorFile: "done, cacheVersion = snapshot"
SaveFile->>SaveFile: snapshot savedDoc + savedVersion
SaveFile->>Disk: writeFile(data)
SaveFile->>Disk: "stat() -> mtime"
SaveFile->>EditorFile: markSaved(mtime, savedDoc, savedVersion)
EditorFile->>EditorFile: "isUnsaved = hasUnsavedChanges()"
Note over User,Disk: Tab switch path
User->>DocSyncListener: switch tab
DocSyncListener->>EditorFile: flushCacheWrite() [background]
EditorFile->>Disk: "writeToCache() if cacheVersion != docVersion"
Reviews (6): Last reviewed commit: "fix(editor): restore format save guard" | Re-trigger Greptile |
Uh oh!
There was an error while loading. Please reload this page.