From d25c6b15a69b2c3dcb3c78f61d7ef5ead8148f9f Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Sun, 16 Oct 2022 12:55:02 -0600 Subject: [PATCH] Move Terminal key down event handling from element to View::key_down method --- crates/terminal/src/terminal_element.rs | 39 ++++--------------------- crates/terminal/src/terminal_view.rs | 15 ++++++++++ 2 files changed, 20 insertions(+), 34 deletions(-) diff --git a/crates/terminal/src/terminal_element.rs b/crates/terminal/src/terminal_element.rs index df745dae46..1568cf67d6 100644 --- a/crates/terminal/src/terminal_element.rs +++ b/crates/terminal/src/terminal_element.rs @@ -15,9 +15,8 @@ use gpui::{ }, serde_json::json, text_layout::{Line, RunStyle}, - Element, ElementBox, Event, EventContext, FontCache, KeyDownEvent, ModelContext, MouseButton, - MouseRegion, PaintContext, Quad, SizeConstraint, TextLayoutCache, WeakModelHandle, - WeakViewHandle, + Element, ElementBox, EventContext, FontCache, ModelContext, MouseButton, MouseRegion, + PaintContext, Quad, SizeConstraint, TextLayoutCache, WeakModelHandle, WeakViewHandle, }; use itertools::Itertools; use ordered_float::OrderedFloat; @@ -801,42 +800,14 @@ impl Element for TerminalElement { fn dispatch_event( &mut self, - event: &gpui::Event, + _: &gpui::Event, _bounds: gpui::geometry::rect::RectF, _visible_bounds: gpui::geometry::rect::RectF, _layout: &mut Self::LayoutState, _paint: &mut Self::PaintState, - cx: &mut gpui::EventContext, + _: &mut gpui::EventContext, ) -> bool { - if let Event::KeyDown(KeyDownEvent { keystroke, .. }) = event { - if !cx.is_parent_view_focused() { - return false; - } - - if let Some(view) = self.view.upgrade(cx.app) { - view.update(cx.app, |view, cx| { - view.clear_bel(cx); - view.pause_cursor_blinking(cx); - }) - } - - self.terminal - .upgrade(cx.app) - .map(|model_handle| { - model_handle.update(cx.app, |term, cx| { - term.try_keystroke( - keystroke, - cx.global::() - .terminal_overrides - .option_as_meta - .unwrap_or(false), - ) - }) - }) - .unwrap_or(false) - } else { - false - } + false } fn metadata(&self) -> Option<&dyn std::any::Any> { diff --git a/crates/terminal/src/terminal_view.rs b/crates/terminal/src/terminal_view.rs index 0058198dc2..1e6788deeb 100644 --- a/crates/terminal/src/terminal_view.rs +++ b/crates/terminal/src/terminal_view.rs @@ -357,6 +357,21 @@ impl View for TerminalView { cx.notify(); } + fn key_down(&mut self, event: &gpui::KeyDownEvent, cx: &mut ViewContext) -> bool { + self.clear_bel(cx); + self.pause_cursor_blinking(cx); + + self.terminal.update(cx, |term, cx| { + term.try_keystroke( + &event.keystroke, + cx.global::() + .terminal_overrides + .option_as_meta + .unwrap_or(false), + ) + }) + } + //IME stuff fn selected_text_range(&self, cx: &AppContext) -> Option> { if self