Skip to content

feat: preserve scroll, cursor, and undo across tab switches - #421

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/preserve-scroll-position
Apr 13, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/preserve-scroll-position

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Apr 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Monaco editors now save and restore scroll position, cursor position, and undo history when switching between tabs, instead of resetting to the top of the file each time
  • Adds cursorPositionCache alongside existing scrollTopCache (module-scoped Maps with LRU eviction at 20 entries)
  • Uses keepCurrentModel / keepCurrentOriginalModel / keepCurrentModifiedModel to retain Monaco models (and their undo stacks) across unmount/remount
  • Disposes kept-alive models and clears caches when tabs are closed (not just switched away from)
  • Works for .md preview
  • Works for regular files
  • Works for diff viewer files

Changes

File What
scroll-cache.ts Add cursorPositionCache map
MonacoEditor.tsx Save cursor on move, snapshot scroll+cursor on unmount (useLayoutEffect), restore both on mount (requestAnimationFrame), add keepCurrentModel
DiffViewer.tsx Add filePath prop, throttled scroll save/restore, useLayoutEffect unmount snapshot, keepCurrentOriginalModel / keepCurrentModifiedModel, stable model paths
EditorContent.tsx Add key={activeFile.id} and filePath on <DiffViewer> to force unmount/remount on tab switch
EditorPanel.tsx Cleanup effect: dispose models + clear caches when tabs are closed

Test plan

Verified via Electron CDP automation (Chrome DevTools Protocol against the running app) — 9/9 tests passed:

Test Result Details
Scroll restored after tab switch ✅ Set 500px on 1961-line file, switched away and back, got 500px
Cursor restored after tab switch ✅ Set L50:C5, switched away and back, got L50:C5
Insert applied ✅ Prepended text to line 1 via pushEditOperations
Undo before switch ✅ model.undo() reverts the insert
Undo after switch ✅ model.undo() still works after switching tabs and back (keepCurrentModel preserves undo stack)
Multiple models retained ✅ 2 models alive simultaneously after visiting both tabs
docker-compose model alive ✅ Model persists after switching away
pnpm-lock model alive ✅ Model persists after switching away
Short file cursor restore ✅ L10:C3 on 18-line file preserved across tab switch

…witches

Monaco editors now save and restore scroll position, cursor position,
and undo history when switching between tabs, instead of resetting to
the top of the file each time.

Changes:
- Add cursorPositionCache alongside existing scrollTopCache (LRU, 20 entries)
- Save cursor on every cursor move and snapshot scroll+cursor on unmount
  via useLayoutEffect cleanup (runs before editor disposal)
- Restore scroll+cursor on mount via requestAnimationFrame (after layout)
- Add keepCurrentModel to MonacoEditor so undo history survives unmount
- Add keepCurrentOriginalModel/keepCurrentModifiedModel + scroll
  save/restore to DiffViewer
- Add key={activeFile.id} on DiffViewer to force unmount/remount on
  tab switch (triggers save/restore lifecycle)
- Dispose kept-alive models and clear caches when tabs are closed
  (EditorPanel cleanup effect)
The revert in 94ac805 removed a guard that prevented scrollTop=0 from
clobbering valid cached positions during React StrictMode double-mount.
Restore the guard in useEditorScrollRestore and MarkdownPreview, and
clean up :rich/:preview scoped cache keys on tab close.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/preserve-scroll-position branch from 6370531 to fa50532 Compare April 13, 2026 22:09
@brennanb2025
brennanb2025 merged commit 114c0d1 into main Apr 13, 2026
1 check passed
@brennanb2025
brennanb2025 deleted the brennanb2025/preserve-scroll-position branch April 13, 2026 22:23
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
Thundernerd added a commit to Thundernerd/orca that referenced this pull request Nov 18, 2026
… of tickets

Each implemented ticket handed over one to three findings in the area it had
just touched, and each of those did the same, so the tracker filled with
narrowing variations on one theme (on Cronk: stablyai#421 → stablyai#430 → stablyai#442/stablyai#443 →
stablyai#448/stablyai#454 → stablyai#460/stablyai#461, and similar chains for closing, query binding and
From Transcript kinds). Some were review points on code still on the
unmerged branch (stablyai#450, stablyai#453) or /code-review judgement calls (stablyai#467).

- The implementing brief, local and cloud, now counts only real bugs and
  gaps as findings. Problems in code the branch adds are fixed in its PR;
  judgement calls, tidy-ups and further passes over freshly reworked code
  are left with a reason in the report instead of handed over.
- The finding check also searches tickets closed in the last two weeks and
  the findings already filed up the "Found while implementing" chain, and
  files nothing for code that exists only on the origin's branch.
- A finding whose title is already recorded on its origin is not filed
  again, which is how stablyai#431 duplicated stablyai#430.
- The filed body no longer repeats "Found while implementing" and the
  triage line when the agent's draft already opens with them.
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