Implement movement in editor2 (#3256)

Release Notes:

- N/A
This commit is contained in:
Antonio Scandurra 2023-11-07 19:12:09 +01:00 committed by GitHub
commit 4bf3a4e3d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 639 additions and 481 deletions

View file

@ -300,7 +300,8 @@ impl Window {
/// When constructing the element tree, we maintain a stack of key dispatch frames until we
/// find the focused element. We interleave key listeners with dispatch contexts so we can use the
/// contexts when matching key events against the keymap.
/// contexts when matching key events against the keymap. A key listener can be either an action
/// handler or a [KeyDown] / [KeyUp] event listener.
enum KeyDispatchStackFrame {
Listener {
event_type: TypeId,
@ -1048,6 +1049,10 @@ impl<'a> WindowContext<'a> {
/// Dispatch a mouse or keyboard event on the window.
pub fn dispatch_event(&mut self, event: InputEvent) -> bool {
// Handlers may set this to false by calling `stop_propagation`
self.app.propagate_event = true;
self.window.default_prevented = false;
let event = match event {
// Track the mouse position with our own state, since accessing the platform
// API for the mouse position can only occur on the main thread.
@ -1101,10 +1106,6 @@ impl<'a> WindowContext<'a> {
};
if let Some(any_mouse_event) = event.mouse_event() {
// Handlers may set this to false by calling `stop_propagation`
self.app.propagate_event = true;
self.window.default_prevented = false;
if let Some(mut handlers) = self
.window
.mouse_listeners
@ -1314,6 +1315,7 @@ impl<'a> WindowContext<'a> {
} = stack_frame
{
if action_type == *event_type {
self.app.propagate_event = false;
listener(action.as_any(), &[], DispatchPhase::Bubble, self);
if !self.app.propagate_event {
break;
@ -1328,6 +1330,7 @@ impl<'a> WindowContext<'a> {
self.app.global_action_listeners.remove(&action_type)
{
for listener in global_listeners.iter().rev() {
self.app.propagate_event = false;
listener(action.as_ref(), DispatchPhase::Bubble, self);
if !self.app.propagate_event {
break;