pane: Add keybinding to "Close Left" and "Close Right" actions (#22402)

Was super missing these as I use these actions all the time 😄 

<img width="680" alt="Screenshot 2024-12-24 at 3 18 04 PM"
src="https://github.com/user-attachments/assets/5dbf9ebd-afc5-438c-aad7-c17ca59d9f9b"
/>

Release Notes:

- Add keybinding to "Close Left" and "Close Right" actions
This commit is contained in:
Danilo Leal 2024-12-26 10:22:08 -03:00 committed by GitHub
parent 95911aaa14
commit 2957263b23
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 4 deletions

View file

@ -260,6 +260,8 @@
"ctrl-f4": "pane::CloseActiveItem", "ctrl-f4": "pane::CloseActiveItem",
"alt-ctrl-t": ["pane::CloseInactiveItems", { "close_pinned": false }], "alt-ctrl-t": ["pane::CloseInactiveItems", { "close_pinned": false }],
"alt-ctrl-shift-w": "workspace::CloseInactiveTabsAndPanes", "alt-ctrl-shift-w": "workspace::CloseInactiveTabsAndPanes",
"ctrl-k e": ["pane::CloseItemsToTheLeft", { "close_pinned": false }],
"ctrl-k t": ["pane::CloseItemsToTheRight", { "close_pinned": false }],
"ctrl-k u": ["pane::CloseCleanItems", { "close_pinned": false }], "ctrl-k u": ["pane::CloseCleanItems", { "close_pinned": false }],
"ctrl-k w": ["pane::CloseAllItems", { "close_pinned": false }], "ctrl-k w": ["pane::CloseAllItems", { "close_pinned": false }],
"ctrl-shift-f": "project_search::ToggleFocus", "ctrl-shift-f": "project_search::ToggleFocus",

View file

@ -327,6 +327,8 @@
"cmd-w": "pane::CloseActiveItem", "cmd-w": "pane::CloseActiveItem",
"alt-cmd-t": ["pane::CloseInactiveItems", { "close_pinned": false }], "alt-cmd-t": ["pane::CloseInactiveItems", { "close_pinned": false }],
"ctrl-alt-cmd-w": "workspace::CloseInactiveTabsAndPanes", "ctrl-alt-cmd-w": "workspace::CloseInactiveTabsAndPanes",
"cmd-k e": ["pane::CloseItemsToTheLeft", { "close_pinned": false }],
"cmd-k t": ["pane::CloseItemsToTheRight", { "close_pinned": false }],
"cmd-k u": ["pane::CloseCleanItems", { "close_pinned": false }], "cmd-k u": ["pane::CloseCleanItems", { "close_pinned": false }],
"cmd-k cmd-w": ["pane::CloseAllItems", { "close_pinned": false }], "cmd-k cmd-w": ["pane::CloseAllItems", { "close_pinned": false }],
"cmd-f": "project_search::ToggleFocus", "cmd-f": "project_search::ToggleFocus",

View file

@ -1234,12 +1234,13 @@ impl Pane {
} }
let active_item_id = self.items[self.active_item_index].item_id(); let active_item_id = self.items[self.active_item_index].item_id();
let non_closeable_items = self.get_non_closeable_item_ids(action.close_pinned); let non_closeable_items = self.get_non_closeable_item_ids(action.close_pinned);
Some(self.close_items_to_the_left_by_id(active_item_id, non_closeable_items, cx)) Some(self.close_items_to_the_left_by_id(active_item_id, action, non_closeable_items, cx))
} }
pub fn close_items_to_the_left_by_id( pub fn close_items_to_the_left_by_id(
&mut self, &mut self,
item_id: EntityId, item_id: EntityId,
action: &CloseItemsToTheLeft,
non_closeable_items: Vec<EntityId>, non_closeable_items: Vec<EntityId>,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Task<Result<()>> { ) -> Task<Result<()>> {
@ -1249,7 +1250,9 @@ impl Pane {
.map(|item| item.item_id()) .map(|item| item.item_id())
.collect(); .collect();
self.close_items(cx, SaveIntent::Close, move |item_id| { self.close_items(cx, SaveIntent::Close, move |item_id| {
item_ids.contains(&item_id) && !non_closeable_items.contains(&item_id) item_ids.contains(&item_id)
&& !action.close_pinned
&& !non_closeable_items.contains(&item_id)
}) })
} }
@ -1263,12 +1266,13 @@ impl Pane {
} }
let active_item_id = self.items[self.active_item_index].item_id(); let active_item_id = self.items[self.active_item_index].item_id();
let non_closeable_items = self.get_non_closeable_item_ids(action.close_pinned); let non_closeable_items = self.get_non_closeable_item_ids(action.close_pinned);
Some(self.close_items_to_the_right_by_id(active_item_id, non_closeable_items, cx)) Some(self.close_items_to_the_right_by_id(active_item_id, action, non_closeable_items, cx))
} }
pub fn close_items_to_the_right_by_id( pub fn close_items_to_the_right_by_id(
&mut self, &mut self,
item_id: EntityId, item_id: EntityId,
action: &CloseItemsToTheRight,
non_closeable_items: Vec<EntityId>, non_closeable_items: Vec<EntityId>,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Task<Result<()>> { ) -> Task<Result<()>> {
@ -1279,7 +1283,9 @@ impl Pane {
.map(|item| item.item_id()) .map(|item| item.item_id())
.collect(); .collect();
self.close_items(cx, SaveIntent::Close, move |item_id| { self.close_items(cx, SaveIntent::Close, move |item_id| {
item_ids.contains(&item_id) && !non_closeable_items.contains(&item_id) item_ids.contains(&item_id)
&& !action.close_pinned
&& !non_closeable_items.contains(&item_id)
}) })
} }
@ -2244,6 +2250,9 @@ impl Pane {
cx.handler_for(&pane, move |pane, cx| { cx.handler_for(&pane, move |pane, cx| {
pane.close_items_to_the_left_by_id( pane.close_items_to_the_left_by_id(
item_id, item_id,
&CloseItemsToTheLeft {
close_pinned: false,
},
pane.get_non_closeable_item_ids(false), pane.get_non_closeable_item_ids(false),
cx, cx,
) )
@ -2258,6 +2267,9 @@ impl Pane {
cx.handler_for(&pane, move |pane, cx| { cx.handler_for(&pane, move |pane, cx| {
pane.close_items_to_the_right_by_id( pane.close_items_to_the_right_by_id(
item_id, item_id,
&CloseItemsToTheRight {
close_pinned: false,
},
pane.get_non_closeable_item_ids(false), pane.get_non_closeable_item_ids(false),
cx, cx,
) )