From 726c8eb43f6ba0a58aac182fa311e0bce7fda49b Mon Sep 17 00:00:00 2001 From: Petros Amoiridis Date: Mon, 13 Mar 2023 11:42:40 +0200 Subject: [PATCH] Use type_id to determine what has the focus Co-Authored-By: Antonio Scandurra --- crates/gpui/src/app.rs | 6 ++++++ crates/terminal_view/src/terminal_button.rs | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 7fc1de83fd..51208f3930 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -2757,6 +2757,12 @@ impl AppContext { Some(self.views.get(&(window_id, view_id))?.ui_name()) } + pub fn view_type_id(&self, window_id: usize, view_id: usize) -> Option { + self.views + .get(&(window_id, view_id)) + .map(|view| view.as_any().type_id()) + } + pub fn background(&self) -> &Arc { &self.background } diff --git a/crates/terminal_view/src/terminal_button.rs b/crates/terminal_view/src/terminal_button.rs index c3efb43fb4..c4f4c0571f 100644 --- a/crates/terminal_view/src/terminal_button.rs +++ b/crates/terminal_view/src/terminal_button.rs @@ -5,6 +5,7 @@ use gpui::{ ViewHandle, WeakModelHandle, WeakViewHandle, }; use settings::Settings; +use std::any::TypeId; use terminal::Terminal; use workspace::{dock::FocusDock, item::ItemHandle, NewTerminal, StatusItemView, Workspace}; @@ -50,7 +51,9 @@ impl View for TerminalButton { let focused_view = cx.focused_view_id(cx.window_id()); let active = focused_view - .map(|view| cx.view_ui_name(cx.window_id(), view) == Some(TerminalView::ui_name())) + .map(|view_id| { + cx.view_type_id(cx.window_id(), view_id) == Some(TypeId::of::()) + }) .unwrap_or(false); let has_terminals = !project.local_terminal_handles().is_empty();