fix(editor): stabilize restored selection and loading state which was causing two edge cases#2168
Conversation
… causing two edge cases
Greptile SummaryThis PR fixes two editor state restoration edge cases: it eliminates the "loading..." placeholder that was polluting undo history and causing visible flicker, and it ensures persisted selections are always collapsed to single cursor positions to prevent out-of-bounds errors on restore.
Confidence Score: 4/5The core loading-state and savedDoc fixes are sound, but the setTimeout cursor/scroll restoration path still applies to the global editor regardless of which tab is active, meaning a background file finishing its load can silently move the cursor or scroll position of the tab the user is currently looking at. The two-phase emit pattern, the direct field assignment for background-tab editable state, and the savedDoc disk-read fix are all correct. The one concern is that restoreSelection and setScrollPosition inside the setTimeout callback use the global editor reference with no active-tab guard — so when a background file finishes loading, its saved cursor and scroll are applied to whatever file the user is currently viewing. src/lib/editorFile.js — the setTimeout block at the end of #loadText needs a guard to skip cursor and scroll restoration when the loaded file is not the active tab. Important Files Changed
Sequence DiagramsequenceDiagram
participant LT as #loadText()
participant EM as editorManager
participant AFE as applyFileToEditor()
LT->>LT: "setReadOnly(true), loading=true"
LT->>EM: emit("file-loaded") [interim, active tab only]
EM->>AFE: applyFileToEditor(file)
AFE->>AFE: isReusableEditorState? → fast-path: old doc, read-only
LT->>LT: read cache (if exists)
LT->>LT: "read disk → savedDoc = EditorState.create({doc: diskValue}).doc"
LT->>LT: "session = EditorState.create({doc: value})"
LT->>LT: "__cmSessionReady = false"
LT->>LT: "markLoaded({savedDoc})"
LT->>EM: emit("file-loaded") [final, active tab only]
EM->>AFE: applyFileToEditor(file)
AFE->>AFE: "isReusableEditorState? → false (__cmSessionReady=false)"
AFE->>AFE: create full state with doc + all extensions
AFE->>AFE: "__cmSessionReady = true"
LT->>LT: setTimeout: restoreSelection + restoreFolds
Reviews (2): Last reviewed commit: "fix" | Re-trigger Greptile |
No description provided.