Move Terminal key down event handling from element to View::key_down method

This commit is contained in:
Nathan Sobo 2022-10-16 12:55:02 -06:00
parent b9308ad80d
commit d25c6b15a6
2 changed files with 20 additions and 34 deletions

View file

@ -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::<Settings>()
.terminal_overrides
.option_as_meta
.unwrap_or(false),
)
})
})
.unwrap_or(false)
} else {
false
}
false
}
fn metadata(&self) -> Option<&dyn std::any::Any> {

View file

@ -357,6 +357,21 @@ impl View for TerminalView {
cx.notify();
}
fn key_down(&mut self, event: &gpui::KeyDownEvent, cx: &mut ViewContext<Self>) -> bool {
self.clear_bel(cx);
self.pause_cursor_blinking(cx);
self.terminal.update(cx, |term, cx| {
term.try_keystroke(
&event.keystroke,
cx.global::<Settings>()
.terminal_overrides
.option_as_meta
.unwrap_or(false),
)
})
}
//IME stuff
fn selected_text_range(&self, cx: &AppContext) -> Option<std::ops::Range<usize>> {
if self