From b9ed327b944556cbe33682685ca7b1aa9f66413c Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 5 May 2023 10:08:22 +0200 Subject: [PATCH] Replace usages of `is_parent_view_focused` with `is_self_focused` Previously, this was used because we didn't have access to the current view and `EventContext` was an element-only abstraction. Now that the `EventContext` wraps the current view's `ViewContext` we can simply check for the view's focus and avoid querying ancestors. --- crates/gpui/src/app.rs | 8 -------- crates/terminal_view/src/terminal_element.rs | 4 ++-- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index fa09f3b859..450be671da 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -2859,14 +2859,6 @@ impl<'a, 'b, V: View> ViewContext<'a, 'b, V> { self.window.focused_view_id == Some(self.view_id) } - pub fn is_parent_view_focused(&self) -> bool { - if let Some(parent_view_id) = self.ancestors(self.view_id).next().clone() { - self.focused_view_id() == Some(parent_view_id) - } else { - false - } - } - pub fn focus_parent(&mut self) { let window_id = self.window_id; let view_id = self.view_id; diff --git a/crates/terminal_view/src/terminal_element.rs b/crates/terminal_view/src/terminal_element.rs index eb2d68910f..ae2342cd97 100644 --- a/crates/terminal_view/src/terminal_element.rs +++ b/crates/terminal_view/src/terminal_element.rs @@ -408,7 +408,7 @@ impl TerminalElement { ) // Update drag selections .on_drag(MouseButton::Left, move |event, _: &mut TerminalView, cx| { - if cx.is_parent_view_focused() { + if cx.is_self_focused() { if let Some(conn_handle) = connection.upgrade(cx) { conn_handle.update(cx, |terminal, cx| { terminal.mouse_drag(event, origin); @@ -444,7 +444,7 @@ impl TerminalElement { }, ) .on_move(move |event, _: &mut TerminalView, cx| { - if cx.is_parent_view_focused() { + if cx.is_self_focused() { if let Some(conn_handle) = connection.upgrade(cx) { conn_handle.update(cx, |terminal, cx| { terminal.mouse_move(&event, origin);