Skip to content

Fix preview button acting on the focused editor instead of its own pane - #61218

Merged
ChristopherBiscardi merged 1 commit into
zed-industries:mainfrom
austincummings:fix-preview-button-pane-targeting
Jul 20, 2026
Merged

Fix preview button acting on the focused editor instead of its own pane#61218
ChristopherBiscardi merged 1 commit into
zed-industries:mainfrom
austincummings:fix-preview-button-pane-targeting

Conversation

@austincummings

Copy link
Copy Markdown
Collaborator

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. 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

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jul 17, 2026
@zed-community-bot zed-community-bot Bot added the guild Pull requests by someone in Zed Guild. NOTE: the label application is automated via github actions label Jul 17, 2026
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
austincummings force-pushed the fix-preview-button-pane-targeting branch from d862ce6 to 01fbca3 Compare July 17, 2026 18:43

@ChristopherBiscardi ChristopherBiscardi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@ChristopherBiscardi
ChristopherBiscardi added this pull request to the merge queue Jul 20, 2026
@ChristopherBiscardi ChristopherBiscardi self-assigned this Jul 20, 2026
Merged via the queue into zed-industries:main with commit 339d96b Jul 20, 2026
35 checks passed
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement guild Pull requests by someone in Zed Guild. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown preview button in UI targets active cursor focus instead of the associated pane/tab

2 participants