From 2a973109d47ab41dd8158a82b818e48d216dd647 Mon Sep 17 00:00:00 2001 From: CharlesChen0823 Date: Mon, 26 May 2025 21:40:19 +0800 Subject: [PATCH] pane: Add functional clone on drop with `control` modifier (#29921) Release Notes: - Added a way to split and clone tab on with alt (macOS) / ctrl-mouse drop --- crates/workspace/src/pane.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index b4e293a5d7462665196c374380b838a12ab69c61..ad3eff848a058cc52b31ea35ebc4fb784a87de18 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -2833,6 +2833,9 @@ impl Pane { } } + let is_clone = cfg!(target_os = "macos") && window.modifiers().alt + || cfg!(not(target_os = "macos")) && window.modifiers().control; + let from_pane = dragged_tab.pane.clone(); self.workspace .update(cx, |_, cx| { @@ -2840,9 +2843,26 @@ impl Pane { if let Some(split_direction) = split_direction { to_pane = workspace.split_pane(to_pane, split_direction, window, cx); } + let database_id = workspace.database_id(); let old_ix = from_pane.read(cx).index_for_item_id(item_id); let old_len = to_pane.read(cx).items.len(); - move_item(&from_pane, &to_pane, item_id, ix, window, cx); + if is_clone { + let Some(item) = from_pane + .read(cx) + .items() + .find(|item| item.item_id() == item_id) + .map(|item| item.clone()) + else { + return; + }; + if let Some(item) = item.clone_on_split(database_id, window, cx) { + to_pane.update(cx, |pane, cx| { + pane.add_item(item, true, true, None, window, cx); + }) + } + } else { + move_item(&from_pane, &to_pane, item_id, ix, window, cx); + } if to_pane == from_pane { if let Some(old_index) = old_ix { to_pane.update(cx, |this, _| {