Skip to content

fix: each tab keeps its own preview or editor mode - #45

Merged
seamoss merged 2 commits into
seamoss:mainfrom
productengineered:fix/per-tab-preview-mode
Sep 29, 2026
Merged

seamoss merged 2 commits into
seamoss:mainfrom
productengineered:fix/per-tab-preview-mode

Conversation

@productengineered

Copy link
Copy Markdown
Contributor

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() called exitPreview() on every tab switch and never entered preview again, so switching tabs always meant the editor.
  • The open rule (existing clean file → preview; new, empty or restored-dirty → editor) only ran for the document that was displayed when it loaded. Tabs opened in the background never got it.

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.
  • After that only the user changes it (⌘E, double-click, Escape, Find, …). 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 previewing class 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 through exitPreview(). Preview also 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 test 328 / pnpm typecheck clean. No version bump, per the usual.

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.
@seamoss
seamoss merged commit 57d52d3 into seamoss:main Sep 29, 2026
1 check passed
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.

2 participants