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
This commit is contained in:
CharlesChen0823 2025-05-26 21:40:19 +08:00 committed by GitHub
parent 2e62f16149
commit 2a973109d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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, _| {