mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-20 02:47:34 +03:00
commit
a86f401a7c
@ -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
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user