Skip to content

Add check to prevent closing pinned items#50333

Merged
JosephTLyons merged 5 commits intozed-industries:mainfrom
austincummings:fix-middle-click-closes-pinned-tab
Mar 27, 2026
Merged

Add check to prevent closing pinned items#50333
JosephTLyons merged 5 commits intozed-industries:mainfrom
austincummings:fix-middle-click-closes-pinned-tab

Conversation

@austincummings
Copy link
Copy Markdown
Contributor

@austincummings austincummings commented Feb 27, 2026

Pinned items should not be closed when the close action is triggered.

Closes #50309

Before you mark this PR as ready for review, make sure that you have:

  • Added a solid test coverage and/or screenshots from doing manual testing
  • Done a self-review taking into account security and performance aspects
  • Aligned any UI changes with the UI checklist

Release Notes:

  • Fixed a bug where middle-clicking a pinned tab would close it.

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 27, 2026
@cppcoffee
Copy link
Copy Markdown
Contributor

Perhaps such modifications would be better:

   1 diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs
   2 index 66e5eeb473..0d025ac350 100644
   3 --- a/crates/workspace/src/pane.rs
   4 +++ b/crates/workspace/src/pane.rs
   5 @@ -2859,7 +2859,7 @@ impl Pane {
   6              }))
   7              .on_aux_click(
   8                  cx.listener(move |pane: &mut Self, event: &ClickEvent, window, cx| {
   9 -                    if !event.is_middle_click() {
  10 +                    if !event.is_middle_click() || is_pinned {
  11                          return;
  12                      }
  13

Pinned items should not be closed when the close action is triggered.
@austincummings austincummings force-pushed the fix-middle-click-closes-pinned-tab branch from a9c7c8f to 0a5c70d Compare March 2, 2026 15:14
@seanstrom
Copy link
Copy Markdown
Contributor

@austincummings It's possible that we could also add an automated test for this functionality. I think there are some examples in the crates/workspace/src/pane.rs file.

For example, I think we can simulate the middle-click event like this:

cx.simulate_event(MouseDownEvent {
    position: tab_a_bounds.center(),
    button: MouseButton::Middle,
    modifiers: Modifiers::default(),
    click_count: 1,
    first_mouse: false,
});

cx.run_until_parked();

cx.simulate_event(MouseUpEvent {
    position: tab_a_bounds.center(),
    button: MouseButton::Middle,
    modifiers: Modifiers::default(),
    click_count: 1,
});

cx.run_until_parked();

There's more code needed for the entire test, here's an entire test function for reference: https://github.com/seanstrom/zed/blob/083cdcf6348aecdfd4770735bd50b9e0a578b741/crates/workspace/src/pane.rs#L6804-L6868

@JosephTLyons
Copy link
Copy Markdown
Collaborator

JosephTLyons commented Mar 27, 2026

Thanks for this fix @austincummings. I agree with @seanstrom that we should have a test in place to keep this behavior pinned. Sean's test looks great, testing a middle click on both a pinned and an unpinned tab, and ensuring the first remains and the second is closed.

Test that middle-clicking a pinned tab does not close it, while
middle-clicking an unpinned tab does close it as expected.
@austincummings
Copy link
Copy Markdown
Contributor Author

Added a test!

@JosephTLyons
Copy link
Copy Markdown
Collaborator

Perfect. Thank you!

@JosephTLyons
Copy link
Copy Markdown
Collaborator

JosephTLyons commented Mar 27, 2026

@austincummings, can you fix the failing CI? It is just an unused import. Also, if you could rebase on main and force push, just so this branch is up to date, that would be awesome. Thank you for your work!

@austincummings
Copy link
Copy Markdown
Contributor Author

@JosephTLyons yep my bad! Fixed

@JosephTLyons JosephTLyons merged commit 9d6208b into zed-industries:main Mar 27, 2026
30 checks passed
@JosephTLyons
Copy link
Copy Markdown
Collaborator

Thank you!

@JosephTLyons
Copy link
Copy Markdown
Collaborator

@zed-zippy approved

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Middle click closes a pinned tab

4 participants