editor: Add ToggleFocus action (#34495)

This PR adds action `editor: toggle focus` which focuses to last active
editor pane item in workspace.

Release Notes:

- Added `editor: toggle focus` action, which focuses to last active
editor pane item.

---------

Co-authored-by: Danilo Leal <daniloleal09@gmail.com>
This commit is contained in:
Smit Barmase 2025-07-16 01:47:40 +05:30 committed by GitHub
parent 572d3d637a
commit 0ada4ce900
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 36 additions and 0 deletions

View file

@ -425,6 +425,8 @@ actions!(
FoldRecursive,
/// Folds the selected ranges.
FoldSelectedRanges,
/// Toggles focus back to the last active buffer.
ToggleFocus,
/// Toggles folding at the current position.
ToggleFold,
/// Toggles recursive folding at the current position.

View file

@ -356,6 +356,7 @@ pub fn init(cx: &mut App) {
workspace.register_action(Editor::new_file_vertical);
workspace.register_action(Editor::new_file_horizontal);
workspace.register_action(Editor::cancel_language_server_work);
workspace.register_action(Editor::toggle_focus);
},
)
.detach();
@ -16954,6 +16955,18 @@ impl Editor {
cx.notify();
}
pub fn toggle_focus(
workspace: &mut Workspace,
_: &actions::ToggleFocus,
window: &mut Window,
cx: &mut Context<Workspace>,
) {
let Some(item) = workspace.recent_active_item_by_type::<Self>(cx) else {
return;
};
workspace.activate_item(&item, true, true, window, cx);
}
pub fn toggle_fold(
&mut self,
_: &actions::ToggleFold,