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

@ -1711,6 +1711,27 @@ impl Workspace {
history
}
pub fn recent_active_item_by_type<T: 'static>(&self, cx: &App) -> Option<Entity<T>> {
let mut recent_item: Option<Entity<T>> = None;
let mut recent_timestamp = 0;
for pane_handle in &self.panes {
let pane = pane_handle.read(cx);
let item_map: HashMap<EntityId, &Box<dyn ItemHandle>> =
pane.items().map(|item| (item.item_id(), item)).collect();
for entry in pane.activation_history() {
if entry.timestamp > recent_timestamp {
if let Some(&item) = item_map.get(&entry.entity_id) {
if let Some(typed_item) = item.act_as::<T>(cx) {
recent_timestamp = entry.timestamp;
recent_item = Some(typed_item);
}
}
}
}
}
recent_item
}
pub fn recent_navigation_history_iter(
&self,
cx: &App,