From 42ef3e5d3d5c738be20b1a1edfc91ff1cbb364c7 Mon Sep 17 00:00:00 2001 From: Tim Vermeulen Date: Mon, 29 Sep 2025 21:30:06 +0200 Subject: [PATCH] editor: Make cmd-alt-click behavior more consistent (#38733) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes two inconsistencies around the behavior of cmd-alt-click that mess with my VSCode muscle memory: - The definition is opened in a pane to the right of the current pane, unless there exists an adjacent pane to the left and not to the right, in which case it's opened in the pane on the left - In case Go to Definition needs to open a multibuffer, cmd-alt-click does not open it in an existing pane to the right of the current pane, it always creates a new pane directly to the right of the current pane This PR irons out this behavior by always going to the definition in the pane directly to the right of the current one, creating one only if one doesn't yet exist. If changing `Workspace::adjacent_pane` to not consider an existing pane to the left is undesirable then that logic could be moved somewhere else, or we can make it user configurable if necessary. Also happy to split this PR up if either of these changes is controversial 🙂 Before: https://github.com/user-attachments/assets/395754cd-6ecb-40bf-ae61-ee8903eed4ae After: https://github.com/user-attachments/assets/002797b1-51a7-48e5-a8d0-100d3a5049eb Release Notes: - Made the behavior of cmd-alt-click more consistent --------- Co-authored-by: Joseph T. Lyons --- crates/editor/src/editor.rs | 3 ++- crates/workspace/src/workspace.rs | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 406dd395ba..1c440c2192 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -16918,7 +16918,8 @@ impl Editor { let item_id = item.item_id(); if split { - workspace.split_item(SplitDirection::Right, item, window, cx); + let pane = workspace.adjacent_pane(window, cx); + workspace.add_item(pane, item, None, true, true, window, cx); } else if PreviewTabsSettings::get_global(cx).enable_preview_from_code_navigation { let (preview_item_id, preview_item_idx) = workspace.active_pane().read_with(cx, |pane, _| { diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index c286a0e5de..3b10f0c883 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -4176,7 +4176,6 @@ impl Workspace { pub fn adjacent_pane(&mut self, window: &mut Window, cx: &mut Context) -> Entity { self.find_pane_in_direction(SplitDirection::Right, cx) - .or_else(|| self.find_pane_in_direction(SplitDirection::Left, cx)) .unwrap_or_else(|| { self.split_pane(self.active_pane.clone(), SplitDirection::Right, window, cx) })