Move Terminal key down event handling from element to View::key_down method
This commit is contained in:
parent
b9308ad80d
commit
d25c6b15a6
2 changed files with 20 additions and 34 deletions
|
@ -15,9 +15,8 @@ use gpui::{
|
||||||
},
|
},
|
||||||
serde_json::json,
|
serde_json::json,
|
||||||
text_layout::{Line, RunStyle},
|
text_layout::{Line, RunStyle},
|
||||||
Element, ElementBox, Event, EventContext, FontCache, KeyDownEvent, ModelContext, MouseButton,
|
Element, ElementBox, EventContext, FontCache, ModelContext, MouseButton, MouseRegion,
|
||||||
MouseRegion, PaintContext, Quad, SizeConstraint, TextLayoutCache, WeakModelHandle,
|
PaintContext, Quad, SizeConstraint, TextLayoutCache, WeakModelHandle, WeakViewHandle,
|
||||||
WeakViewHandle,
|
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use ordered_float::OrderedFloat;
|
use ordered_float::OrderedFloat;
|
||||||
|
@ -801,42 +800,14 @@ impl Element for TerminalElement {
|
||||||
|
|
||||||
fn dispatch_event(
|
fn dispatch_event(
|
||||||
&mut self,
|
&mut self,
|
||||||
event: &gpui::Event,
|
_: &gpui::Event,
|
||||||
_bounds: gpui::geometry::rect::RectF,
|
_bounds: gpui::geometry::rect::RectF,
|
||||||
_visible_bounds: gpui::geometry::rect::RectF,
|
_visible_bounds: gpui::geometry::rect::RectF,
|
||||||
_layout: &mut Self::LayoutState,
|
_layout: &mut Self::LayoutState,
|
||||||
_paint: &mut Self::PaintState,
|
_paint: &mut Self::PaintState,
|
||||||
cx: &mut gpui::EventContext,
|
_: &mut gpui::EventContext,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if let Event::KeyDown(KeyDownEvent { keystroke, .. }) = event {
|
false
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn metadata(&self) -> Option<&dyn std::any::Any> {
|
fn metadata(&self) -> Option<&dyn std::any::Any> {
|
||||||
|
|
|
@ -357,6 +357,21 @@ impl View for TerminalView {
|
||||||
cx.notify();
|
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
|
//IME stuff
|
||||||
fn selected_text_range(&self, cx: &AppContext) -> Option<std::ops::Range<usize>> {
|
fn selected_text_range(&self, cx: &AppContext) -> Option<std::ops::Range<usize>> {
|
||||||
if self
|
if self
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue