interactive.rs

  1use crate::{
  2    Bounds, Capslock, Context, Empty, IntoElement, Keystroke, Modifiers, Pixels, Point, Render,
  3    Window, point, seal::Sealed,
  4};
  5use smallvec::SmallVec;
  6use std::{any::Any, fmt::Debug, ops::Deref, path::PathBuf};
  7
  8/// An event from a platform input source.
  9pub trait InputEvent: Sealed + 'static {
 10    /// Convert this event into the platform input enum.
 11    fn to_platform_input(self) -> PlatformInput;
 12}
 13
 14/// A key event from the platform.
 15pub trait KeyEvent: InputEvent {}
 16
 17/// A mouse event from the platform.
 18pub trait MouseEvent: InputEvent {}
 19
 20/// A gesture event from the platform.
 21pub trait GestureEvent: InputEvent {}
 22
 23/// The key down event equivalent for the platform.
 24#[derive(Clone, Debug, Eq, PartialEq)]
 25pub struct KeyDownEvent {
 26    /// The keystroke that was generated.
 27    pub keystroke: Keystroke,
 28
 29    /// Whether the key is currently held down.
 30    pub is_held: bool,
 31
 32    /// Whether to prefer character input over keybindings for this keystroke.
 33    /// In some cases, like AltGr on Windows, modifiers are significant for character input.
 34    pub prefer_character_input: bool,
 35}
 36
 37impl Sealed for KeyDownEvent {}
 38impl InputEvent for KeyDownEvent {
 39    fn to_platform_input(self) -> PlatformInput {
 40        PlatformInput::KeyDown(self)
 41    }
 42}
 43impl KeyEvent for KeyDownEvent {}
 44
 45/// The key up event equivalent for the platform.
 46#[derive(Clone, Debug)]
 47pub struct KeyUpEvent {
 48    /// The keystroke that was released.
 49    pub keystroke: Keystroke,
 50}
 51
 52impl Sealed for KeyUpEvent {}
 53impl InputEvent for KeyUpEvent {
 54    fn to_platform_input(self) -> PlatformInput {
 55        PlatformInput::KeyUp(self)
 56    }
 57}
 58impl KeyEvent for KeyUpEvent {}
 59
 60/// The modifiers changed event equivalent for the platform.
 61#[derive(Clone, Debug, Default)]
 62pub struct ModifiersChangedEvent {
 63    /// The new state of the modifier keys
 64    pub modifiers: Modifiers,
 65    /// The new state of the capslock key
 66    pub capslock: Capslock,
 67}
 68
 69impl Sealed for ModifiersChangedEvent {}
 70impl InputEvent for ModifiersChangedEvent {
 71    fn to_platform_input(self) -> PlatformInput {
 72        PlatformInput::ModifiersChanged(self)
 73    }
 74}
 75impl KeyEvent for ModifiersChangedEvent {}
 76
 77impl Deref for ModifiersChangedEvent {
 78    type Target = Modifiers;
 79
 80    fn deref(&self) -> &Self::Target {
 81        &self.modifiers
 82    }
 83}
 84
 85/// The phase of a touch motion event.
 86/// Based on the winit enum of the same name.
 87#[derive(Clone, Copy, Debug, Default)]
 88pub enum TouchPhase {
 89    /// The touch started.
 90    Started,
 91    /// The touch event is moving.
 92    #[default]
 93    Moved,
 94    /// The touch phase has ended
 95    Ended,
 96}
 97
 98/// A mouse down event from the platform
 99#[derive(Clone, Debug, Default)]
100pub struct MouseDownEvent {
101    /// Which mouse button was pressed.
102    pub button: MouseButton,
103
104    /// The position of the mouse on the window.
105    pub position: Point<Pixels>,
106
107    /// The modifiers that were held down when the mouse was pressed.
108    pub modifiers: Modifiers,
109
110    /// The number of times the button has been clicked.
111    pub click_count: usize,
112
113    /// Whether this is the first, focusing click.
114    pub first_mouse: bool,
115}
116
117impl Sealed for MouseDownEvent {}
118impl InputEvent for MouseDownEvent {
119    fn to_platform_input(self) -> PlatformInput {
120        PlatformInput::MouseDown(self)
121    }
122}
123impl MouseEvent for MouseDownEvent {}
124
125impl MouseDownEvent {
126    /// Returns true if this mouse up event should focus the element.
127    pub fn is_focusing(&self) -> bool {
128        match self.button {
129            MouseButton::Left => true,
130            _ => false,
131        }
132    }
133}
134
135/// A mouse up event from the platform
136#[derive(Clone, Debug, Default)]
137pub struct MouseUpEvent {
138    /// Which mouse button was released.
139    pub button: MouseButton,
140
141    /// The position of the mouse on the window.
142    pub position: Point<Pixels>,
143
144    /// The modifiers that were held down when the mouse was released.
145    pub modifiers: Modifiers,
146
147    /// The number of times the button has been clicked.
148    pub click_count: usize,
149}
150
151impl Sealed for MouseUpEvent {}
152impl InputEvent for MouseUpEvent {
153    fn to_platform_input(self) -> PlatformInput {
154        PlatformInput::MouseUp(self)
155    }
156}
157
158impl MouseEvent for MouseUpEvent {}
159
160impl MouseUpEvent {
161    /// Returns true if this mouse up event should focus the element.
162    pub fn is_focusing(&self) -> bool {
163        match self.button {
164            MouseButton::Left => true,
165            _ => false,
166        }
167    }
168}
169
170/// A click event, generated when a mouse button is pressed and released.
171#[derive(Clone, Debug, Default)]
172pub struct MouseClickEvent {
173    /// The mouse event when the button was pressed.
174    pub down: MouseDownEvent,
175
176    /// The mouse event when the button was released.
177    pub up: MouseUpEvent,
178}
179
180/// The stage of a pressure click event.
181#[derive(Clone, Copy, Debug, Default, PartialEq)]
182pub enum PressureStage {
183    /// No pressure.
184    #[default]
185    Zero,
186    /// Normal click pressure.
187    Normal,
188    /// High pressure, enough to trigger a force click.
189    Force,
190}
191
192/// A mouse pressure event from the platform. Generated when a force-sensitive trackpad is pressed hard.
193/// Currently only implemented for macOS trackpads.
194#[derive(Debug, Clone, Default)]
195pub struct MousePressureEvent {
196    /// Pressure of the current stage as a float between 0 and 1
197    pub pressure: f32,
198    /// The pressure stage of the event.
199    pub stage: PressureStage,
200    /// The position of the mouse on the window.
201    pub position: Point<Pixels>,
202    /// The modifiers that were held down when the mouse pressure changed.
203    pub modifiers: Modifiers,
204}
205
206impl Sealed for MousePressureEvent {}
207impl InputEvent for MousePressureEvent {
208    fn to_platform_input(self) -> PlatformInput {
209        PlatformInput::MousePressure(self)
210    }
211}
212impl MouseEvent for MousePressureEvent {}
213
214/// A click event that was generated by a keyboard button being pressed and released.
215#[derive(Clone, Debug, Default)]
216pub struct KeyboardClickEvent {
217    /// The keyboard button that was pressed to trigger the click.
218    pub button: KeyboardButton,
219
220    /// The bounds of the element that was clicked.
221    pub bounds: Bounds<Pixels>,
222}
223
224/// A click event, generated when a mouse button or keyboard button is pressed and released.
225#[derive(Clone, Debug)]
226pub enum ClickEvent {
227    /// A click event trigger by a mouse button being pressed and released.
228    Mouse(MouseClickEvent),
229    /// A click event trigger by a keyboard button being pressed and released.
230    Keyboard(KeyboardClickEvent),
231}
232
233impl Default for ClickEvent {
234    fn default() -> Self {
235        ClickEvent::Keyboard(KeyboardClickEvent::default())
236    }
237}
238
239impl ClickEvent {
240    /// Returns the modifiers that were held during the click event
241    ///
242    /// `Keyboard`: The keyboard click events never have modifiers.
243    /// `Mouse`: Modifiers that were held during the mouse key up event.
244    pub fn modifiers(&self) -> Modifiers {
245        match self {
246            // Click events are only generated from keyboard events _without any modifiers_, so we know the modifiers are always Default
247            ClickEvent::Keyboard(_) => Modifiers::default(),
248            // Click events on the web only reflect the modifiers for the keyup event,
249            // tested via observing the behavior of the `ClickEvent.shiftKey` field in Chrome 138
250            // under various combinations of modifiers and keyUp / keyDown events.
251            ClickEvent::Mouse(event) => event.up.modifiers,
252        }
253    }
254
255    /// Returns the position of the click event
256    ///
257    /// `Keyboard`: The bottom left corner of the clicked hitbox
258    /// `Mouse`: The position of the mouse when the button was released.
259    pub fn position(&self) -> Point<Pixels> {
260        match self {
261            ClickEvent::Keyboard(event) => event.bounds.bottom_left(),
262            ClickEvent::Mouse(event) => event.up.position,
263        }
264    }
265
266    /// Returns the mouse position of the click event
267    ///
268    /// `Keyboard`: None
269    /// `Mouse`: The position of the mouse when the button was released.
270    pub fn mouse_position(&self) -> Option<Point<Pixels>> {
271        match self {
272            ClickEvent::Keyboard(_) => None,
273            ClickEvent::Mouse(event) => Some(event.up.position),
274        }
275    }
276
277    /// Returns if this was a right click
278    ///
279    /// `Keyboard`: false
280    /// `Mouse`: Whether the right button was pressed and released
281    pub fn is_right_click(&self) -> bool {
282        match self {
283            ClickEvent::Keyboard(_) => false,
284            ClickEvent::Mouse(event) => {
285                event.down.button == MouseButton::Right && event.up.button == MouseButton::Right
286            }
287        }
288    }
289
290    /// Returns if this was a middle click
291    ///
292    /// `Keyboard`: false
293    /// `Mouse`: Whether the middle button was pressed and released
294    pub fn is_middle_click(&self) -> bool {
295        match self {
296            ClickEvent::Keyboard(_) => false,
297            ClickEvent::Mouse(event) => {
298                event.down.button == MouseButton::Middle && event.up.button == MouseButton::Middle
299            }
300        }
301    }
302
303    /// Returns whether the click was a standard click
304    ///
305    /// `Keyboard`: Always true
306    /// `Mouse`: Left button pressed and released
307    pub fn standard_click(&self) -> bool {
308        match self {
309            ClickEvent::Keyboard(_) => true,
310            ClickEvent::Mouse(event) => {
311                event.down.button == MouseButton::Left && event.up.button == MouseButton::Left
312            }
313        }
314    }
315
316    /// Returns whether the click focused the element
317    ///
318    /// `Keyboard`: false, keyboard clicks only work if an element is already focused
319    /// `Mouse`: Whether this was the first focusing click
320    pub fn first_focus(&self) -> bool {
321        match self {
322            ClickEvent::Keyboard(_) => false,
323            ClickEvent::Mouse(event) => event.down.first_mouse,
324        }
325    }
326
327    /// Returns the click count of the click event
328    ///
329    /// `Keyboard`: Always 1
330    /// `Mouse`: Count of clicks from MouseUpEvent
331    pub fn click_count(&self) -> usize {
332        match self {
333            ClickEvent::Keyboard(_) => 1,
334            ClickEvent::Mouse(event) => event.up.click_count,
335        }
336    }
337
338    /// Returns whether the click event is generated by a keyboard event
339    pub fn is_keyboard(&self) -> bool {
340        match self {
341            ClickEvent::Mouse(_) => false,
342            ClickEvent::Keyboard(_) => true,
343        }
344    }
345}
346
347/// An enum representing the keyboard button that was pressed for a click event.
348#[derive(Hash, PartialEq, Eq, Copy, Clone, Debug, Default)]
349pub enum KeyboardButton {
350    /// Enter key was clicked
351    #[default]
352    Enter,
353    /// Space key was clicked
354    Space,
355}
356
357/// An enum representing the mouse button that was pressed.
358#[derive(Hash, Default, PartialEq, Eq, Copy, Clone, Debug)]
359pub enum MouseButton {
360    /// The left mouse button.
361    #[default]
362    Left,
363
364    /// The right mouse button.
365    Right,
366
367    /// The middle mouse button.
368    Middle,
369
370    /// A navigation button, such as back or forward.
371    Navigate(NavigationDirection),
372}
373
374impl MouseButton {
375    /// Get all the mouse buttons in a list.
376    pub fn all() -> Vec<Self> {
377        vec![
378            MouseButton::Left,
379            MouseButton::Right,
380            MouseButton::Middle,
381            MouseButton::Navigate(NavigationDirection::Back),
382            MouseButton::Navigate(NavigationDirection::Forward),
383        ]
384    }
385}
386
387/// A navigation direction, such as back or forward.
388#[derive(Hash, Default, PartialEq, Eq, Copy, Clone, Debug)]
389pub enum NavigationDirection {
390    /// The back button.
391    #[default]
392    Back,
393
394    /// The forward button.
395    Forward,
396}
397
398/// A mouse move event from the platform.
399#[derive(Clone, Debug, Default)]
400pub struct MouseMoveEvent {
401    /// The position of the mouse on the window.
402    pub position: Point<Pixels>,
403
404    /// The mouse button that was pressed, if any.
405    pub pressed_button: Option<MouseButton>,
406
407    /// The modifiers that were held down when the mouse was moved.
408    pub modifiers: Modifiers,
409}
410
411impl Sealed for MouseMoveEvent {}
412impl InputEvent for MouseMoveEvent {
413    fn to_platform_input(self) -> PlatformInput {
414        PlatformInput::MouseMove(self)
415    }
416}
417impl MouseEvent for MouseMoveEvent {}
418
419impl MouseMoveEvent {
420    /// Returns true if the left mouse button is currently held down.
421    pub fn dragging(&self) -> bool {
422        self.pressed_button == Some(MouseButton::Left)
423    }
424}
425
426/// A mouse wheel event from the platform.
427#[derive(Clone, Debug, Default)]
428pub struct ScrollWheelEvent {
429    /// The position of the mouse on the window.
430    pub position: Point<Pixels>,
431
432    /// The change in scroll wheel position for this event.
433    pub delta: ScrollDelta,
434
435    /// The modifiers that were held down when the mouse was moved.
436    pub modifiers: Modifiers,
437
438    /// The phase of the touch event.
439    pub touch_phase: TouchPhase,
440}
441
442impl Sealed for ScrollWheelEvent {}
443impl InputEvent for ScrollWheelEvent {
444    fn to_platform_input(self) -> PlatformInput {
445        PlatformInput::ScrollWheel(self)
446    }
447}
448impl MouseEvent for ScrollWheelEvent {}
449
450impl Deref for ScrollWheelEvent {
451    type Target = Modifiers;
452
453    fn deref(&self) -> &Self::Target {
454        &self.modifiers
455    }
456}
457
458/// The scroll delta for a scroll wheel event.
459#[derive(Clone, Copy, Debug)]
460pub enum ScrollDelta {
461    /// An exact scroll delta in pixels.
462    Pixels(Point<Pixels>),
463    /// An inexact scroll delta in lines.
464    Lines(Point<f32>),
465}
466
467impl Default for ScrollDelta {
468    fn default() -> Self {
469        Self::Lines(Default::default())
470    }
471}
472
473/// A pinch gesture event from the platform, generated when the user performs
474/// a pinch-to-zoom gesture (typically on a trackpad).
475///
476#[derive(Clone, Debug, Default)]
477pub struct PinchEvent {
478    /// The position of the pinch center on the window.
479    pub position: Point<Pixels>,
480
481    /// The zoom delta for this event.
482    /// Positive values indicate zooming in, negative values indicate zooming out.
483    /// For example, 0.1 represents a 10% zoom increase.
484    pub delta: f32,
485
486    /// The modifiers that were held down during the pinch gesture.
487    pub modifiers: Modifiers,
488
489    /// The phase of the pinch gesture.
490    pub phase: TouchPhase,
491}
492
493impl Sealed for PinchEvent {}
494impl InputEvent for PinchEvent {
495    fn to_platform_input(self) -> PlatformInput {
496        PlatformInput::Pinch(self)
497    }
498}
499impl GestureEvent for PinchEvent {}
500impl MouseEvent for PinchEvent {}
501
502impl Deref for PinchEvent {
503    type Target = Modifiers;
504
505    fn deref(&self) -> &Self::Target {
506        &self.modifiers
507    }
508}
509
510impl ScrollDelta {
511    /// Returns true if this is a precise scroll delta in pixels.
512    pub fn precise(&self) -> bool {
513        match self {
514            ScrollDelta::Pixels(_) => true,
515            ScrollDelta::Lines(_) => false,
516        }
517    }
518
519    /// Converts this scroll event into exact pixels.
520    pub fn pixel_delta(&self, line_height: Pixels) -> Point<Pixels> {
521        match self {
522            ScrollDelta::Pixels(delta) => *delta,
523            ScrollDelta::Lines(delta) => point(line_height * delta.x, line_height * delta.y),
524        }
525    }
526
527    /// Combines two scroll deltas into one.
528    /// If the signs of the deltas are the same (both positive or both negative),
529    /// the deltas are added together. If the signs are opposite, the second delta
530    /// (other) is used, effectively overriding the first delta.
531    pub fn coalesce(self, other: ScrollDelta) -> ScrollDelta {
532        match (self, other) {
533            (ScrollDelta::Pixels(a), ScrollDelta::Pixels(b)) => {
534                let x = if a.x.signum() == b.x.signum() {
535                    a.x + b.x
536                } else {
537                    b.x
538                };
539
540                let y = if a.y.signum() == b.y.signum() {
541                    a.y + b.y
542                } else {
543                    b.y
544                };
545
546                ScrollDelta::Pixels(point(x, y))
547            }
548
549            (ScrollDelta::Lines(a), ScrollDelta::Lines(b)) => {
550                let x = if a.x.signum() == b.x.signum() {
551                    a.x + b.x
552                } else {
553                    b.x
554                };
555
556                let y = if a.y.signum() == b.y.signum() {
557                    a.y + b.y
558                } else {
559                    b.y
560                };
561
562                ScrollDelta::Lines(point(x, y))
563            }
564
565            _ => other,
566        }
567    }
568}
569
570/// A mouse exit event from the platform, generated when the mouse leaves the window.
571#[derive(Clone, Debug, Default)]
572pub struct MouseExitEvent {
573    /// The position of the mouse relative to the window.
574    pub position: Point<Pixels>,
575    /// The mouse button that was pressed, if any.
576    pub pressed_button: Option<MouseButton>,
577    /// The modifiers that were held down when the mouse was moved.
578    pub modifiers: Modifiers,
579}
580
581impl Sealed for MouseExitEvent {}
582impl InputEvent for MouseExitEvent {
583    fn to_platform_input(self) -> PlatformInput {
584        PlatformInput::MouseExited(self)
585    }
586}
587
588impl MouseEvent for MouseExitEvent {}
589
590impl Deref for MouseExitEvent {
591    type Target = Modifiers;
592
593    fn deref(&self) -> &Self::Target {
594        &self.modifiers
595    }
596}
597
598/// A collection of paths from the platform, such as from a file drop.
599#[derive(Debug, Clone, Default, Eq, PartialEq)]
600pub struct ExternalPaths(pub SmallVec<[PathBuf; 2]>);
601
602impl ExternalPaths {
603    /// Convert this collection of paths into a slice.
604    pub fn paths(&self) -> &[PathBuf] {
605        &self.0
606    }
607}
608
609impl Render for ExternalPaths {
610    fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
611        // the platform will render icons for the dragged files
612        Empty
613    }
614}
615
616/// A file drop event from the platform, generated when files are dragged and dropped onto the window.
617#[derive(Debug, Clone)]
618pub enum FileDropEvent {
619    /// The files have entered the window.
620    Entered {
621        /// The position of the mouse relative to the window.
622        position: Point<Pixels>,
623        /// The paths of the files that are being dragged.
624        paths: ExternalPaths,
625    },
626    /// The files are being dragged over the window
627    Pending {
628        /// The position of the mouse relative to the window.
629        position: Point<Pixels>,
630    },
631    /// The files have been dropped onto the window.
632    Submit {
633        /// The position of the mouse relative to the window.
634        position: Point<Pixels>,
635    },
636    /// The user has stopped dragging the files over the window.
637    Exited,
638}
639
640impl Sealed for FileDropEvent {}
641impl InputEvent for FileDropEvent {
642    fn to_platform_input(self) -> PlatformInput {
643        PlatformInput::FileDrop(self)
644    }
645}
646impl MouseEvent for FileDropEvent {}
647
648/// An enum corresponding to all kinds of platform input events.
649#[derive(Clone, Debug)]
650pub enum PlatformInput {
651    /// A key was pressed.
652    KeyDown(KeyDownEvent),
653    /// A key was released.
654    KeyUp(KeyUpEvent),
655    /// The keyboard modifiers were changed.
656    ModifiersChanged(ModifiersChangedEvent),
657    /// The mouse was pressed.
658    MouseDown(MouseDownEvent),
659    /// The mouse was released.
660    MouseUp(MouseUpEvent),
661    /// Mouse pressure.
662    MousePressure(MousePressureEvent),
663    /// The mouse was moved.
664    MouseMove(MouseMoveEvent),
665    /// The mouse exited the window.
666    MouseExited(MouseExitEvent),
667    /// The scroll wheel was used.
668    ScrollWheel(ScrollWheelEvent),
669    /// A pinch gesture was performed.
670    Pinch(PinchEvent),
671    /// Files were dragged and dropped onto the window.
672    FileDrop(FileDropEvent),
673}
674
675impl PlatformInput {
676    pub(crate) fn mouse_event(&self) -> Option<&dyn Any> {
677        match self {
678            PlatformInput::KeyDown { .. } => None,
679            PlatformInput::KeyUp { .. } => None,
680            PlatformInput::ModifiersChanged { .. } => None,
681            PlatformInput::MouseDown(event) => Some(event),
682            PlatformInput::MouseUp(event) => Some(event),
683            PlatformInput::MouseMove(event) => Some(event),
684            PlatformInput::MousePressure(event) => Some(event),
685            PlatformInput::MouseExited(event) => Some(event),
686            PlatformInput::ScrollWheel(event) => Some(event),
687            PlatformInput::Pinch(event) => Some(event),
688            PlatformInput::FileDrop(event) => Some(event),
689        }
690    }
691
692    pub(crate) fn keyboard_event(&self) -> Option<&dyn Any> {
693        match self {
694            PlatformInput::KeyDown(event) => Some(event),
695            PlatformInput::KeyUp(event) => Some(event),
696            PlatformInput::ModifiersChanged(event) => Some(event),
697            PlatformInput::MouseDown(_) => None,
698            PlatformInput::MouseUp(_) => None,
699            PlatformInput::MouseMove(_) => None,
700            PlatformInput::MousePressure(_) => None,
701            PlatformInput::MouseExited(_) => None,
702            PlatformInput::ScrollWheel(_) => None,
703            PlatformInput::Pinch(_) => None,
704            PlatformInput::FileDrop(_) => None,
705        }
706    }
707}
708
709#[cfg(test)]
710mod test {
711
712    use crate::{
713        self as gpui, AppContext as _, Context, FocusHandle, InteractiveElement, IntoElement,
714        KeyBinding, Keystroke, ParentElement, Render, TestAppContext, Window, div,
715    };
716
717    struct TestView {
718        saw_key_down: bool,
719        saw_action: bool,
720        focus_handle: FocusHandle,
721    }
722
723    actions!(test_only, [TestAction]);
724
725    impl Render for TestView {
726        fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
727            div().id("testview").child(
728                div()
729                    .key_context("parent")
730                    .on_key_down(cx.listener(|this, _, _, cx| {
731                        cx.stop_propagation();
732                        this.saw_key_down = true
733                    }))
734                    .on_action(cx.listener(|this: &mut TestView, _: &TestAction, _, _| {
735                        this.saw_action = true
736                    }))
737                    .child(
738                        div()
739                            .key_context("nested")
740                            .track_focus(&self.focus_handle)
741                            .into_element(),
742                    ),
743            )
744        }
745    }
746
747    #[gpui::test]
748    fn test_on_events(cx: &mut TestAppContext) {
749        let window = cx.update(|cx| {
750            cx.open_window(Default::default(), |_, cx| {
751                cx.new(|cx| TestView {
752                    saw_key_down: false,
753                    saw_action: false,
754                    focus_handle: cx.focus_handle(),
755                })
756            })
757            .unwrap()
758        });
759
760        cx.update(|cx| {
761            cx.bind_keys(vec![KeyBinding::new("ctrl-g", TestAction, Some("parent"))]);
762        });
763
764        window
765            .update(cx, |test_view, window, cx| {
766                window.focus(&test_view.focus_handle, cx)
767            })
768            .unwrap();
769
770        cx.dispatch_keystroke(*window, Keystroke::parse("a").unwrap());
771        cx.dispatch_keystroke(*window, Keystroke::parse("ctrl-g").unwrap());
772
773        window
774            .update(cx, |test_view, _, _| {
775                assert!(test_view.saw_key_down || test_view.saw_action);
776                assert!(test_view.saw_key_down);
777                assert!(test_view.saw_action);
778            })
779            .unwrap();
780    }
781}