Repository navigation
fix(editor): preserve folds and horizontal scroll across tab switches - #34810
Conversation
Move editorViewStateCache into scroll-cache.ts, clear it in the shared model lifetime fixture, drop the e2e evidence spec and the duplicate LRU test.
2e9600e to
fbc6be3
Compare
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 11 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
[Medium impact] The change affects the source-code editor tab-switching workflow. The PR appears safe to merge, with a non-blocking gap in coverage for real tab switches. Findings
SummaryPreserves Monaco's full view state across editor remounts.
Reviews (1) · Last reviewed commit: "refactor(editor): keep editor view state..." · Reviewed by Greptile |
| const restoreViewState = vi.fn() | ||
| // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: restore accesses only these stubbed editor methods. | ||
| const remountedEditor = { | ||
| getModel: sourceEditor.getModel, | ||
| restoreViewState, | ||
| setSelections, | ||
| setScrollTop, | ||
| focus | ||
| } as unknown as editor.IStandaloneCodeEditor | ||
| restoreMonacoViewState(remountedEditor, 'file.ts::tab-1') | ||
|
|
||
| expect(setSelections).toHaveBeenCalledWith(selections) | ||
| expect(setScrollTop).toHaveBeenCalledWith(320) | ||
| expect(restoreViewState).toHaveBeenCalledExactlyOnceWith(viewState) |
There was a problem hiding this comment.
Real tab switches lack coverage
This test passes a hand-written object to a mocked restoreViewState. It never checks that Monaco restores folds or horizontal scroll after a tab switch, so it would pass even if either behavior remained broken. Add a test with a real editor: fold a region, scroll horizontally, switch tabs, then return and check both.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Problem
Switching away from a source tab and back restores only the selection and vertical scroll. Folded regions reopen and horizontal scroll resets to column 0, because
MonacoEditorrecreates the editor on tab switch (saveViewState={false}) and Orca's own snapshot keeps just selections + scrollTop.Fix
Also snapshot Monaco's full
ICodeEditorViewState(cursor, scroll, and contribution state such as folding) into an LRU cache besidediffViewStateCache, keyed by the existing view-state key plus the model URI. On restore, prefer it; otherwise fall back to the existing selection/scrollTop caches. Monaco's folding contribution validates restored folds against the current line count, so external edits don't apply stale folds.Tests
monaco-view-state-persistence.test.tscovers restoring the full viewport, selections and folded regions after a tab remount, and checks that saved folds are not applied to another host or pane showing the same path. Removed the Playwright evidence spec from the original draft.