Moar terminal bugs de2ified (#3894)

Release Notes:

- N/A
This commit is contained in:
Julia 2024-01-04 18:40:55 -05:00 committed by GitHub
commit a86f401a7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 31 deletions

View File

@ -307,7 +307,10 @@ mod test {
div().id("testview").child( div().id("testview").child(
div() div()
.key_context("parent") .key_context("parent")
.on_key_down(cx.listener(|this, _, _| this.saw_key_down = true)) .on_key_down(cx.listener(|this, _, cx| {
cx.stop_propagation();
this.saw_key_down = true
}))
.on_action( .on_action(
cx.listener(|this: &mut TestView, _: &TestAction, _| { cx.listener(|this: &mut TestView, _: &TestAction, _| {
this.saw_action = true this.saw_action = true
@ -343,6 +346,7 @@ mod test {
.update(cx, |test_view, cx| cx.focus(&test_view.focus_handle)) .update(cx, |test_view, cx| cx.focus(&test_view.focus_handle))
.unwrap(); .unwrap();
cx.dispatch_keystroke(*window, Keystroke::parse("a").unwrap(), false);
cx.dispatch_keystroke(*window, Keystroke::parse("ctrl-g").unwrap(), false); cx.dispatch_keystroke(*window, Keystroke::parse("ctrl-g").unwrap(), false);
window window

View File

@ -1583,36 +1583,16 @@ impl<'a> WindowContext<'a> {
let mut actions: Vec<Box<dyn Action>> = Vec::new(); let mut actions: Vec<Box<dyn Action>> = Vec::new();
// Capture phase
let mut context_stack: SmallVec<[KeyContext; 16]> = SmallVec::new(); let mut context_stack: SmallVec<[KeyContext; 16]> = SmallVec::new();
self.propagate_event = true;
for node_id in &dispatch_path { for node_id in &dispatch_path {
let node = self.window.rendered_frame.dispatch_tree.node(*node_id); let node = self.window.rendered_frame.dispatch_tree.node(*node_id);
if let Some(context) = node.context.clone() { if let Some(context) = node.context.clone() {
context_stack.push(context); context_stack.push(context);
} }
for key_listener in node.key_listeners.clone() {
key_listener(event, DispatchPhase::Capture, self);
if !self.propagate_event {
return;
}
}
} }
// Bubble phase
for node_id in dispatch_path.iter().rev() { for node_id in dispatch_path.iter().rev() {
// Handle low level key events
let node = self.window.rendered_frame.dispatch_tree.node(*node_id);
for key_listener in node.key_listeners.clone() {
key_listener(event, DispatchPhase::Bubble, self);
if !self.propagate_event {
return;
}
}
// Match keystrokes // Match keystrokes
let node = self.window.rendered_frame.dispatch_tree.node(*node_id); let node = self.window.rendered_frame.dispatch_tree.node(*node_id);
if node.context.is_some() { if node.context.is_some() {
@ -1633,6 +1613,7 @@ impl<'a> WindowContext<'a> {
self.clear_pending_keystrokes(); self.clear_pending_keystrokes();
} }
self.propagate_event = true;
for action in actions { for action in actions {
self.dispatch_action_on_node(node_id, action.boxed_clone()); self.dispatch_action_on_node(node_id, action.boxed_clone());
if !self.propagate_event { if !self.propagate_event {
@ -1640,6 +1621,31 @@ impl<'a> WindowContext<'a> {
return; return;
} }
} }
// Capture phase
for node_id in &dispatch_path {
let node = self.window.rendered_frame.dispatch_tree.node(*node_id);
for key_listener in node.key_listeners.clone() {
key_listener(event, DispatchPhase::Capture, self);
if !self.propagate_event {
return;
}
}
}
// Bubble phase
for node_id in dispatch_path.iter().rev() {
// Handle low level key events
let node = self.window.rendered_frame.dispatch_tree.node(*node_id);
for key_listener in node.key_listeners.clone() {
key_listener(event, DispatchPhase::Bubble, self);
if !self.propagate_event {
return;
}
}
}
self.dispatch_keystroke_observers(event, None); self.dispatch_keystroke_observers(event, None);
} }

View File

@ -62,15 +62,7 @@ use lazy_static::lazy_static;
actions!( actions!(
terminal, terminal,
[ [Clear, Copy, Paste, ShowCharacterPalette, SearchTest,]
Clear,
Copy,
Paste,
ShowCharacterPalette,
SearchTest,
SendText,
SendKeystroke,
]
); );
///Scrolling is unbearably sluggish by default. Alacritty supports a configurable ///Scrolling is unbearably sluggish by default. Alacritty supports a configurable

View File

@ -57,7 +57,7 @@ pub struct SendText(String);
#[derive(Clone, Debug, Default, Deserialize, PartialEq)] #[derive(Clone, Debug, Default, Deserialize, PartialEq)]
pub struct SendKeystroke(String); pub struct SendKeystroke(String);
impl_actions!(terminal_view, [SendText, SendKeystroke]); impl_actions!(terminal, [SendText, SendKeystroke]);
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
terminal_panel::init(cx); terminal_panel::init(cx);