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:
parent
572d3d637a
commit
0ada4ce900
3 changed files with 36 additions and 0 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue