Fix preview button acting on the focused editor instead of its own pane - #61218
Merged
ChristopherBiscardi merged 1 commit intoJul 20, 2026
Conversation
The quick action bar's preview button (markdown/SVG/CSV) resolved both its visibility and its click target through workspace.active_item(), i.e. the globally focused item, rather than the item of the pane the button belongs to. With two panes open, clicking the eye button in one pane's toolbar previewed the file focused in the other pane, and focusing a non-previewable file in one pane hid the button in every pane. Fix both by making the flow pane-explicit end to end: - The button resolves its preview type from its own toolbar's active_item (each pane has its own QuickActionBar, kept current via set_active_pane_item). - Clicking no longer dispatches the focus-based OpenPreview actions. It resolves the button's pane via Workspace::pane_for and calls new pane-explicit helpers (open_preview_in_pane / open_preview_to_the_side_of_pane) extracted from the action handler bodies in all three preview crates. Keyboard actions keep their focus-based behavior and now route through the same helpers. - Alt-click (open to the side) splits relative to the button's pane via the new Workspace::adjacent_pane_of, which the existing adjacent_pane now delegates to. Also, within the extracted helpers: - Check for an existing preview before constructing a new view instead of building one and discarding it. - Apply the focus flag to the activate-existing branch too, so opening to the side never steals focus, whether the preview is created fresh or already exists (previously a repeat open-to-the-side focused the existing preview while the first open did not). Adds a regression test reproducing the issue's setup: two panes, focus in the second, preview invoked for the first pane's editor. Closes zed-industries#54951
austincummings
force-pushed
the
fix-preview-button-pane-targeting
branch
from
July 17, 2026 18:43
d862ce6 to
01fbca3
Compare
This was referenced Jul 31, 2026
jolutz
pushed a commit
to jolutz/zed
that referenced
this pull request
Aug 8, 2026
…ne (zed-industries#61218) Closes zed-industries#54951 ## Problem The quick action bar's preview button (markdown, SVG, and CSV behind the feature flag) resolved everything through `workspace.active_item()` — the globally *focused* item — instead of the item of the pane the button sits in. With `A.md` in the left pane and focus in `B.md` in the right pane: - Clicking the eye button in **A.md's** toolbar opened a preview of **B.md**, in the right pane. - Focusing a non-previewable file (e.g. `B.sh`) in one pane hid the button in **every** pane's toolbar, making `A.md` unpreviewable by mouse. Clicking the button dispatched the `OpenPreview` action, whose workspace-level handler re-resolved the focused editor — so a click on a specific pane's toolbar was functionally identical to pressing the keybinding, discarding the pane the click happened in. ## Fix Make the flow pane-explicit end to end: - **Visibility:** each pane's `QuickActionBar` resolves the preview type from its own `active_item` (set via `set_active_pane_item`) instead of the workspace's focused item. - **Click:** no more action dispatch. The handler resolves its pane via `Workspace::pane_for` and calls new pane-explicit helpers — `open_preview_in_pane` / `open_preview_to_the_side_of_pane` — extracted from the action-handler bodies in all three preview crates. Keyboard actions keep their focus-based semantics and route through the same helpers with the focused editor and active pane. - **Alt-click** (open in split) now splits relative to the button's pane via the new `Workspace::adjacent_pane_of` (the existing `adjacent_pane` delegates to it). Notably *not* done: focusing the button's pane and re-dispatching the action. `workspace.active_pane` only updates when pane focus-in listeners fire at the end of the next draw, while dispatched actions run before it — the handler would still read the stale pane. ## Additional changes - Existing-preview lookup now happens **before** view construction, instead of building a full preview view (subscriptions, initial parse) and discarding it when one already exists. - The `focus` flag now also applies to the activate-existing branch, so open-to-the-side never steals focus — previously the *first* invocation left focus in the editor but a *repeat* invocation focused the existing preview (and cancelled collaborator-following in that pane as a side effect). - SVG handlers no longer double-check `is_svg_file`; CSV handlers reuse `resolve_active_item_as_csv_editor` instead of inlining it; `is_markdown_file` takes `&App` instead of a needless `&mut Context<V>`. ## Testing - New regression test `preview_opens_for_the_given_pane_not_the_focused_editor` reproducing the issue's setup (two panes, focus in the second, preview invoked for the first pane's editor), asserting the preview opens in the invoking pane bound to that pane's editor with the focused pane untouched. - Markdown/SVG/CSV preview suites and the full `workspace` suite pass; `./script/clippy` is clean. Release Notes: - Fixed the preview button (Markdown/SVG) previewing the focused file instead of the file in the pane the button belongs to when multiple panes are open
playdohface
pushed a commit
to playdohface/zed
that referenced
this pull request
Aug 29, 2026
…ne (zed-industries#61218) Closes zed-industries#54951 ## Problem The quick action bar's preview button (markdown, SVG, and CSV behind the feature flag) resolved everything through `workspace.active_item()` — the globally *focused* item — instead of the item of the pane the button sits in. With `A.md` in the left pane and focus in `B.md` in the right pane: - Clicking the eye button in **A.md's** toolbar opened a preview of **B.md**, in the right pane. - Focusing a non-previewable file (e.g. `B.sh`) in one pane hid the button in **every** pane's toolbar, making `A.md` unpreviewable by mouse. Clicking the button dispatched the `OpenPreview` action, whose workspace-level handler re-resolved the focused editor — so a click on a specific pane's toolbar was functionally identical to pressing the keybinding, discarding the pane the click happened in. ## Fix Make the flow pane-explicit end to end: - **Visibility:** each pane's `QuickActionBar` resolves the preview type from its own `active_item` (set via `set_active_pane_item`) instead of the workspace's focused item. - **Click:** no more action dispatch. The handler resolves its pane via `Workspace::pane_for` and calls new pane-explicit helpers — `open_preview_in_pane` / `open_preview_to_the_side_of_pane` — extracted from the action-handler bodies in all three preview crates. Keyboard actions keep their focus-based semantics and route through the same helpers with the focused editor and active pane. - **Alt-click** (open in split) now splits relative to the button's pane via the new `Workspace::adjacent_pane_of` (the existing `adjacent_pane` delegates to it). Notably *not* done: focusing the button's pane and re-dispatching the action. `workspace.active_pane` only updates when pane focus-in listeners fire at the end of the next draw, while dispatched actions run before it — the handler would still read the stale pane. ## Additional changes - Existing-preview lookup now happens **before** view construction, instead of building a full preview view (subscriptions, initial parse) and discarding it when one already exists. - The `focus` flag now also applies to the activate-existing branch, so open-to-the-side never steals focus — previously the *first* invocation left focus in the editor but a *repeat* invocation focused the existing preview (and cancelled collaborator-following in that pane as a side effect). - SVG handlers no longer double-check `is_svg_file`; CSV handlers reuse `resolve_active_item_as_csv_editor` instead of inlining it; `is_markdown_file` takes `&App` instead of a needless `&mut Context<V>`. ## Testing - New regression test `preview_opens_for_the_given_pane_not_the_focused_editor` reproducing the issue's setup (two panes, focus in the second, preview invoked for the first pane's editor), asserting the preview opens in the invoking pane bound to that pane's editor with the focused pane untouched. - Markdown/SVG/CSV preview suites and the full `workspace` suite pass; `./script/clippy` is clean. Release Notes: - Fixed the preview button (Markdown/SVG) previewing the focused file instead of the file in the pane the button belongs to when multiple panes are open
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.
Closes #54951
Problem
The quick action bar's preview button (markdown, SVG, and CSV behind the feature flag) resolved everything through
workspace.active_item()— the globally focused item — instead of the item of the pane the button sits in. WithA.mdin the left pane and focus inB.mdin the right pane:B.sh) in one pane hid the button in every pane's toolbar, makingA.mdunpreviewable by mouse.Clicking the button dispatched the
OpenPreviewaction, whose workspace-level handler re-resolved the focused editor — so a click on a specific pane's toolbar was functionally identical to pressing the keybinding, discarding the pane the click happened in.Fix
Make the flow pane-explicit end to end:
QuickActionBarresolves the preview type from its ownactive_item(set viaset_active_pane_item) instead of the workspace's focused item.Workspace::pane_forand calls new pane-explicit helpers —open_preview_in_pane/open_preview_to_the_side_of_pane— extracted from the action-handler bodies in all three preview crates. Keyboard actions keep their focus-based semantics and route through the same helpers with the focused editor and active pane.Workspace::adjacent_pane_of(the existingadjacent_panedelegates to it).Notably not done: focusing the button's pane and re-dispatching the action.
workspace.active_paneonly updates when pane focus-in listeners fire at the end of the next draw, while dispatched actions run before it — the handler would still read the stale pane.Additional changes
focusflag now also applies to the activate-existing branch, so open-to-the-side never steals focus — previously the first invocation left focus in the editor but a repeat invocation focused the existing preview (and cancelled collaborator-following in that pane as a side effect).is_svg_file; CSV handlers reuseresolve_active_item_as_csv_editorinstead of inlining it;is_markdown_filetakes&Appinstead of a needless&mut Context<V>.Testing
preview_opens_for_the_given_pane_not_the_focused_editorreproducing the issue's setup (two panes, focus in the second, preview invoked for the first pane's editor), asserting the preview opens in the invoking pane bound to that pane's editor with the focused pane untouched.workspacesuite pass;./script/clippyis clean.Release Notes: