Repository navigation
fix: each tab keeps its own preview or editor mode - #45
Merged
seamoss merged 2 commits intoSep 29, 2026
Merged
Conversation
Mode was one window-wide switch that every tab switch forced to the editor, and a tab opened in the background never got the open rule's preview at all. Each open document now carries its own mode: decided by the open rule when it loads (displayed or not), changed only by the user, saved when the tab leaves the foreground and restored when it returns.
The editor hides in the same task as the tab swap (and as a file opening into the current tab), so the source can't paint while the preview renders. Rendered HTML is cached per source, so returning to an unchanged tab skips the pipeline — a 200 KB document comes back in ~65 ms, not ~170.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Open several files at once, then click back through the tabs: every tab you return to is in the editor, even the ones that opened in preview. Preview vs. editor was one window-wide switch, and it changed for reasons other than the user asking.
Two causes
display()calledexitPreview()on every tab switch and never entered preview again, so switching tabs always meant the editor.The fix: each tab keeps its own mode
OpenDoc.previewing. The open rule sets it when the document loads, whether or not it's displayed. Reloads keep whatever it was; transfers keep the editor, as before.display()saves the outgoing tab's live mode and puts the incoming tab back in its own mode, at its remembered place.No source flash on the way into preview
When a tab switch (or a file opening into the current tab) lands in preview, the
previewingclass goes on in the same task as the buffer swap. The source can't paint while the preview renders, and a failed render still brings the editor back throughexitPreview().Previewalso keeps a small cache (12 entries) of rendered HTML keyed by source, so returning to an unchanged tab skips the pipeline: a 200 KB document comes back in ~65 ms instead of ~170. ⌘E from the editor is unchanged and still renders before hiding the text.Verified in an isolated instance over CDP: open three files → each tab previews on first and repeat visits; ⌘E one tab to the editor, cycle through all → that tab is still in the editor, the others still preview. A MutationObserver + per-frame trace across switches shows the old build passing through an editor-visible state (up to ~160 ms on the large doc). The new build never does.
pnpm test328 /pnpm typecheckclean. No version bump, per the usual.