diff --git a/crates/gpui/src/interactive.rs b/crates/gpui/src/interactive.rs index 6fc7cfc8e8..0be917350d 100644 --- a/crates/gpui/src/interactive.rs +++ b/crates/gpui/src/interactive.rs @@ -307,7 +307,10 @@ mod test { div().id("testview").child( div() .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( cx.listener(|this: &mut TestView, _: &TestAction, _| { this.saw_action = true @@ -343,6 +346,7 @@ mod test { .update(cx, |test_view, cx| cx.focus(&test_view.focus_handle)) .unwrap(); + cx.dispatch_keystroke(*window, Keystroke::parse("a").unwrap(), false); cx.dispatch_keystroke(*window, Keystroke::parse("ctrl-g").unwrap(), false); window diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs index 7b6541c937..71e6cb9e55 100644 --- a/crates/gpui/src/window.rs +++ b/crates/gpui/src/window.rs @@ -1583,36 +1583,16 @@ impl<'a> WindowContext<'a> { let mut actions: Vec> = Vec::new(); - // Capture phase let mut context_stack: SmallVec<[KeyContext; 16]> = SmallVec::new(); - self.propagate_event = true; - for node_id in &dispatch_path { let node = self.window.rendered_frame.dispatch_tree.node(*node_id); if let Some(context) = node.context.clone() { 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() { - // 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 let node = self.window.rendered_frame.dispatch_tree.node(*node_id); if node.context.is_some() { @@ -1633,6 +1613,7 @@ impl<'a> WindowContext<'a> { self.clear_pending_keystrokes(); } + self.propagate_event = true; for action in actions { self.dispatch_action_on_node(node_id, action.boxed_clone()); if !self.propagate_event { @@ -1640,6 +1621,31 @@ impl<'a> WindowContext<'a> { 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); } diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index 70fceae66a..d43508bdbe 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -62,15 +62,7 @@ use lazy_static::lazy_static; actions!( terminal, - [ - Clear, - Copy, - Paste, - ShowCharacterPalette, - SearchTest, - SendText, - SendKeystroke, - ] + [Clear, Copy, Paste, ShowCharacterPalette, SearchTest,] ); ///Scrolling is unbearably sluggish by default. Alacritty supports a configurable diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs index 521efef790..d519523974 100644 --- a/crates/terminal_view/src/terminal_view.rs +++ b/crates/terminal_view/src/terminal_view.rs @@ -57,7 +57,7 @@ pub struct SendText(String); #[derive(Clone, Debug, Default, Deserialize, PartialEq)] pub struct SendKeystroke(String); -impl_actions!(terminal_view, [SendText, SendKeystroke]); +impl_actions!(terminal, [SendText, SendKeystroke]); pub fn init(cx: &mut AppContext) { terminal_panel::init(cx);