Guide API
Skip to main content

tvision_rs/event/
key.rs

1//! `Key` and `KeyEvent` (documented on `Key`).
2
3/// A logical, modifier-free key — the base of a [`KeyEvent`].
4///
5/// Keyboard keys and key-down events.
6///
7/// A keystroke is modeled the idiomatic, crossterm-shaped way: a closed [`Key`]
8/// enum of *physical* keys plus a *separate* [`KeyModifiers`] channel. There are
9/// deliberately **no** modifier-combined variants: `Ctrl+C` is `Key::Char('c')`
10/// plus `ctrl`, `Shift+Tab` is `Key::Tab` plus `shift`, and `Alt+F3` is
11/// `Key::F(3)` plus `alt`. A [`KeyEvent`] pairs a key with the modifiers active
12/// when it was pressed.
13///
14/// There is no "no key" value: the absence of a keystroke is the absence of a
15/// key event.
16///
17/// Only the 16 base keys appear here; modifier combinations are expressed by
18/// pairing a `Key` with a [`KeyModifiers`] in a [`KeyEvent`]:
19///
20/// - `Ctrl+C` → `Key::Char('c')` + `modifiers.ctrl = true`
21/// - `Shift+Tab` → `Key::Tab` + `modifiers.shift = true`
22/// - `Alt+F3` → `Key::F(3)` + `modifiers.alt = true`
23///
24/// This replaces the ~150 `kb*` combined key+modifier constants from `tkeys.h`;
25/// each constant was a specific bitwise combination of a scan code and a
26/// modifier mask. Here the two dimensions are orthogonal and independently
27/// matchable.
28///
29/// There is no `BackTab` variant. Shift+Tab is `Key::Tab` with `shift` set.
30/// Raw hardware scan codes are not preserved (they are DOS-era platform data
31/// with no cross-platform meaning).
32///
33/// # Turbo Vision heritage
34///
35/// Ports the `kb*` key-code family, the `TKey` class (`tkeys.h` / `tkey.cpp`),
36/// and `KeyDownEvent` (`system.h`). `TKey`'s canonical form already decomposes
37/// each keystroke into a base code plus a modifier mask (Ctrl+A is `'A'` with the
38/// ctrl-shift mask; Shift+Tab is the Tab code with the shift mask); tvision-rs keeps
39/// that decomposition as the [`Key`] enum and a separate [`KeyModifiers`]
40/// (deviations D4 and D5).
41///
42/// Ports the `kb*` key-code family (`tkeys.h`) and the `TKey` canonical form
43/// (`tkeys.h` / `tkey.cpp`); the 1992 guide's `charCode: Char` (low byte) maps
44/// to `Key::Char(char)` carrying the full Unicode character. Deviations D4 and D5.
45#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
46pub enum Key {
47    /// A printable character: letters, digits, symbols, and space.
48    ///
49    /// Holds the base character case-as-typed; case modification and
50    /// Ctrl/Alt semantics live in the accompanying [`KeyModifiers`].
51    /// The 1992 guide's `charCode: Char` (low byte of `keyCode: Word`) maps
52    /// here, extended to full Unicode.
53    Char(char),
54    /// A function key, `F(1)`..=`F(12)`.
55    F(u8),
56    /// The Enter/Return key.
57    Enter,
58    /// The Escape key.
59    Esc,
60    /// The Backspace key.
61    Backspace,
62    /// The Tab key. Note there is no `BackTab` variant: Shift+Tab is `Tab` + the
63    /// `shift` modifier.
64    Tab,
65    /// The Up arrow key.
66    Up,
67    /// The Down arrow key.
68    Down,
69    /// The Left arrow key.
70    Left,
71    /// The Right arrow key.
72    Right,
73    /// The Home key.
74    Home,
75    /// The End key.
76    End,
77    /// The Page Up key.
78    PageUp,
79    /// The Page Down key.
80    PageDown,
81    /// The Insert key.
82    Insert,
83    /// The Delete key.
84    Delete,
85}
86
87/// The keyboard modifiers active when a key or mouse event occurred — a struct
88/// of three named `bool` flags.
89///
90/// Used in both [`KeyEvent`] (keyboard) and [`super::MouseEvent`] (mouse) to
91/// represent the held modifiers at event time. Check individual flags in a
92/// handler:
93///
94/// ```
95/// use tvision_rs::event::{Event, Key};
96/// fn handle(ev: &Event) {
97///     if let Event::KeyDown(ke) = ev {
98///         if ke.key == Key::Char('c') && ke.modifiers.ctrl {
99///             // Ctrl+C
100///         }
101///     }
102/// }
103/// ```
104///
105/// Only three logical modifiers are tracked; left- vs. right-side (e.g.
106/// `kbLeftShift` / `kbRightShift`) collapse into a single flag each. This is
107/// sufficient for all standard TUI key bindings.
108///
109/// # Turbo Vision heritage
110///
111/// The packed `controlKeyState` bit-word (`kbShift`, `kbCtrlShift`,
112/// `kbAltShift`, plus left/right variants) becomes a struct-of-bools (deviation
113/// D5). Left/right-side bits are folded into one flag each.
114#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
115pub struct KeyModifiers {
116    /// Shift (either side) is held.
117    pub shift: bool,
118    /// Ctrl (either side) is held.
119    pub ctrl: bool,
120    /// Alt (either side) is held.
121    pub alt: bool,
122}
123
124/// A key-down event: the logical [`Key`] that was pressed plus the
125/// [`KeyModifiers`] held at that moment.
126///
127/// This is the direct analog of magiblot's `TKey` canonical form (which
128/// already decomposed a keystroke into base code + modifier mask). Construct
129/// with [`KeyEvent::from`] for the no-modifier case, or [`KeyEvent::new`] with
130/// explicit modifiers:
131///
132/// ```
133/// use tvision_rs::event::{Key, KeyEvent, KeyModifiers};
134/// // Enter with no modifiers:
135/// let enter = KeyEvent::from(Key::Enter);
136/// // Ctrl+S:
137/// let ctrl_s = KeyEvent::new(Key::Char('s'), KeyModifiers { ctrl: true, ..Default::default() });
138/// ```
139///
140/// Match a `KeyEvent` in [`View::handle_event`](crate::view::View::handle_event) by
141/// destructuring `Event::KeyDown(ke)` and checking `ke.key` and `ke.modifiers`.
142///
143/// # Turbo Vision heritage
144///
145/// Ports the `KeyDownEvent` sub-record (`system.h`) and the `TKey` canonical
146/// form (`tkeys.h`/`tkey.cpp`). `TKey` already decomposed each keystroke into
147/// base code + modifier mask; tvision-rs keeps that decomposition as the [`Key`]
148/// enum + [`KeyModifiers`] (deviations D4 and D5).
149#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
150pub struct KeyEvent {
151    /// The logical key that was pressed, without modifier encoding.
152    pub key: Key,
153    /// The modifiers (shift, ctrl, alt) held while the key was pressed.
154    pub modifiers: KeyModifiers,
155}
156
157impl KeyEvent {
158    /// A key event with explicit modifiers.
159    pub fn new(key: Key, modifiers: KeyModifiers) -> Self {
160        KeyEvent { key, modifiers }
161    }
162}
163
164/// The common no-modifier case: `KeyEvent::from(Key::Enter)` yields an event
165/// with all modifiers cleared.
166impl From<Key> for KeyEvent {
167    fn from(key: Key) -> Self {
168        KeyEvent {
169            key,
170            modifiers: KeyModifiers::default(),
171        }
172    }
173}
174
175/// Extract the hotkey character from a label string.
176///
177/// The convention: the first `~`-delimited run in `s` marks the hotkey. The
178/// char immediately following the first `~` is the hotkey, **uppercased**.
179/// Returns `None` if there is no `~`, if the `~` is at the end of the string
180/// (nothing after it), or if the char after `~` is itself `~` (a tilde-escape,
181/// i.e. a literal `~` in the label).
182///
183/// # Turbo Vision heritage
184/// Ports `hotKey`/`hotKeyStr` (`tinputli.cpp`); they returned a null char for the
185/// no-hotkey case, where tvision-rs returns `Option<char>`.
186///
187/// # Examples
188///
189/// ```
190/// use tvision_rs::event::hot_key;
191/// assert_eq!(hot_key("~o~k"), Some('O'));  // uppercased
192/// assert_eq!(hot_key("O~k"), Some('K'));  // first char after first '~'
193/// assert_eq!(hot_key("No tilde here"), None);
194/// assert_eq!(hot_key("trailing~"), None);
195/// assert_eq!(hot_key("~~x"), None);       // char after '~' is '~'
196/// ```
197pub fn hot_key(s: &str) -> Option<char> {
198    // Split on the first '~'; the right side is everything after it.
199    let (_, after) = s.split_once('~')?;
200    // Take the first char after '~'.
201    let ch = after.chars().next()?;
202    // If it is itself '~', treat as an escaped tilde — no hotkey.
203    if ch == '~' {
204        return None;
205    }
206    Some(ch.to_ascii_uppercase())
207}
208
209/// Map WordStar Ctrl-letter navigation keys to their arrow/nav equivalents.
210///
211/// In the decomposed key model, a Ctrl-letter is `Key::Char(letter)` with
212/// `modifiers.ctrl` set. The 11-entry table maps:
213///
214/// | Ctrl+ | → Key |
215/// |-------|-------|
216/// | S     | Left  |
217/// | D     | Right |
218/// | E     | Up    |
219/// | X     | Down  |
220/// | A     | Home  |
221/// | F     | End   |
222/// | G     | Delete |
223/// | V     | Insert |
224/// | R     | PageUp |
225/// | C     | PageDown |
226/// | H     | Backspace |
227///
228/// The letter is matched case-insensitively. On a match the resulting
229/// [`KeyEvent`] has **all modifiers cleared** (only the base arrow/nav key is
230/// returned). Any key that does not match — including literal arrow keys,
231/// non-Char keys, or Char keys without `ctrl` — is returned unchanged.
232///
233/// **When to call:** pass an incoming `KeyDown` event through this function
234/// *before* dispatching it for navigation — e.g. in `InputLine::handle_event`
235/// and `Editor::handle_event` — so that applications supporting WordStar-style
236/// navigation can use either arrow keys or the traditional Ctrl-letter chords.
237/// Widgets that do **not** want WordStar mode (e.g. plain text fields that use
238/// Ctrl letters for cut/copy/paste) should skip this call.
239///
240/// # Turbo Vision heritage
241/// Ports `ctrlToArrow` (`drivers2.cpp`).
242pub fn ctrl_to_arrow(ke: KeyEvent) -> KeyEvent {
243    if !ke.modifiers.ctrl {
244        return ke;
245    }
246    let mapped = match ke.key {
247        Key::Char(c) => match c.to_ascii_lowercase() {
248            's' => Some(Key::Left),
249            'd' => Some(Key::Right),
250            'e' => Some(Key::Up),
251            'x' => Some(Key::Down),
252            'a' => Some(Key::Home),
253            'f' => Some(Key::End),
254            'g' => Some(Key::Delete),
255            'v' => Some(Key::Insert),
256            'r' => Some(Key::PageUp),
257            'c' => Some(Key::PageDown),
258            'h' => Some(Key::Backspace),
259            _ => None,
260        },
261        _ => None,
262    };
263    match mapped {
264        Some(key) => KeyEvent {
265            key,
266            modifiers: KeyModifiers::default(),
267        },
268        None => ke,
269    }
270}
271
272/// Test whether a key event is the Alt-accelerator for a given hotkey char.
273///
274/// Together with [`is_plain_hotkey`] (and optionally [`ctrl_to_arrow`] for
275/// WordStar nav pre-processing), these predicates implement hotkey-accelerator
276/// matching for buttons, clusters, and labels. Callers compose them with the
277/// phase/focus gate.
278///
279/// Returns `true` iff:
280/// - `ke.modifiers.alt` is set, **and**
281/// - `ke.key` is `Key::Char(c)` where `c` matches `hot` case-insensitively.
282///
283/// Any `Alt+Char` is accepted case-insensitively; in practice hotkeys are always
284/// letters or digits. Only `alt` is required; `shift` and `ctrl` are not checked.
285///
286/// # Turbo Vision heritage
287/// Replaces the `event.keyDown.keyCode == getAltCode(c)` accelerator idiom
288/// (`tbutton.cpp`, `tcluster.cpp`, `tlabel.cpp`). The original `getAltCode` was a
289/// whitelist of `A–Z`, `0–9`, `-`, `=`; this predicate is deliberately broader.
290/// The Alt-Space special case is dropped.
291pub fn is_alt_hotkey(ke: &KeyEvent, hot: char) -> bool {
292    if !ke.modifiers.alt {
293        return false;
294    }
295    matches!(ke.key, Key::Char(c) if c.eq_ignore_ascii_case(&hot))
296}
297
298/// Test whether a key event is a plain (non-modified) hotkey press.
299///
300/// Returns `true` iff:
301/// - neither `alt` nor `ctrl` is held, **and**
302/// - `ke.key` is `Key::Char(c)` where `c` matches `hot` case-insensitively.
303///
304/// **Why `!alt && !ctrl` is required:** in the decomposed key model Ctrl+S is
305/// `Key::Char('s')` + `ctrl`, so omitting the `ctrl` check would let
306/// `is_plain_hotkey(Ctrl+S, 'S')` false-match. Since Ctrl makes [`is_alt_hotkey`]
307/// false, the call falls through to this predicate, so guarding both modifiers is
308/// what keeps a plain-letter press distinct from a modified one. **Callers still
309/// own the phase gate** (post-process / focused), not this helper.
310pub fn is_plain_hotkey(ke: &KeyEvent, hot: char) -> bool {
311    if ke.modifiers.alt || ke.modifiers.ctrl {
312        return false;
313    }
314    matches!(ke.key, Key::Char(c) if c.eq_ignore_ascii_case(&hot))
315}
316
317#[cfg(test)]
318mod tests {
319    use super::*;
320
321    #[test]
322    fn char_variant_holds_letters_digits_and_space() {
323        assert_eq!(Key::Char('a'), Key::Char('a'));
324        assert_ne!(Key::Char('a'), Key::Char('b'));
325        // Space is just Char(' ').
326        assert_eq!(Key::Char(' '), Key::Char(' '));
327        // Digits and symbols are ordinary characters too.
328        assert_ne!(Key::Char('1'), Key::Char('!'));
329    }
330
331    #[test]
332    fn function_keys_span_f1_to_f12() {
333        assert_eq!(Key::F(1), Key::F(1));
334        assert_ne!(Key::F(1), Key::F(2));
335        // F11/F12 exist (kbF11/kbF12 in tkeys.h).
336        let _ = Key::F(11);
337        let _ = Key::F(12);
338    }
339
340    #[test]
341    fn named_keys_are_distinct() {
342        let keys = [
343            Key::Enter,
344            Key::Esc,
345            Key::Backspace,
346            Key::Tab,
347            Key::Up,
348            Key::Down,
349            Key::Left,
350            Key::Right,
351            Key::Home,
352            Key::End,
353            Key::PageUp,
354            Key::PageDown,
355            Key::Insert,
356            Key::Delete,
357        ];
358        for (i, a) in keys.iter().enumerate() {
359            for (j, b) in keys.iter().enumerate() {
360                assert_eq!(i == j, a == b);
361            }
362        }
363    }
364
365    #[test]
366    fn no_modifier_constructor_clears_all_modifiers() {
367        let ev = KeyEvent::from(Key::Enter);
368        assert_eq!(ev.key, Key::Enter);
369        assert!(!ev.modifiers.shift);
370        assert!(!ev.modifiers.ctrl);
371        assert!(!ev.modifiers.alt);
372        assert_eq!(ev.modifiers, KeyModifiers::default());
373    }
374
375    #[test]
376    fn new_carries_explicit_modifiers() {
377        let mods = KeyModifiers {
378            ctrl: true,
379            ..Default::default()
380        };
381        let ev = KeyEvent::new(Key::Char('c'), mods);
382        assert_eq!(ev.key, Key::Char('c'));
383        assert_eq!(ev.modifiers, mods);
384    }
385
386    #[test]
387    fn shift_tab_is_tab_plus_shift_not_a_backtab_variant() {
388        // The decomposition contract: there is no BackTab variant — Shift+Tab is
389        // the Tab key plus the shift modifier.
390        let ev = KeyEvent::new(
391            Key::Tab,
392            KeyModifiers {
393                shift: true,
394                ..Default::default()
395            },
396        );
397        assert_eq!(ev.key, Key::Tab);
398        assert!(ev.modifiers.shift);
399        assert!(!ev.modifiers.ctrl);
400        assert!(!ev.modifiers.alt);
401    }
402
403    #[test]
404    fn ctrl_c_is_char_plus_ctrl() {
405        // Ctrl+C is modeled as the base char 'c' plus the ctrl modifier.
406        let ev = KeyEvent::new(
407            Key::Char('c'),
408            KeyModifiers {
409                ctrl: true,
410                ..Default::default()
411            },
412        );
413        assert_eq!(ev.key, Key::Char('c'));
414        assert!(ev.modifiers.ctrl);
415        assert!(!ev.modifiers.shift);
416        assert!(!ev.modifiers.alt);
417    }
418
419    #[test]
420    fn alt_f3_is_function_key_plus_alt() {
421        // Alt+F3 decomposes into F(3) + alt.
422        let ev = KeyEvent::new(
423            Key::F(3),
424            KeyModifiers {
425                alt: true,
426                ..Default::default()
427            },
428        );
429        assert_eq!(ev.key, Key::F(3));
430        assert!(ev.modifiers.alt);
431        assert!(!ev.modifiers.ctrl);
432        assert!(!ev.modifiers.shift);
433    }
434
435    // --- hot_key tests ---
436
437    #[test]
438    fn hot_key_tilde_delimited_returns_uppercase_first_char() {
439        // Input uses a lowercase 'o' so the uppercasing step is actually exercised.
440        assert_eq!(hot_key("~o~k"), Some('O'));
441    }
442
443    #[test]
444    fn hot_key_char_after_first_tilde_uppercased() {
445        // First char after the first '~' (which is 'k'), uppercased.
446        assert_eq!(hot_key("O~k"), Some('K'));
447    }
448
449    #[test]
450    fn hot_key_no_tilde_returns_none() {
451        assert_eq!(hot_key("No tilde here"), None);
452        assert_eq!(hot_key(""), None);
453    }
454
455    #[test]
456    fn hot_key_trailing_tilde_returns_none() {
457        assert_eq!(hot_key("trailing~"), None);
458    }
459
460    #[test]
461    fn hot_key_double_tilde_escape_returns_none() {
462        // The char immediately after the first '~' is another '~' — no hotkey.
463        assert_eq!(hot_key("~~x"), None);
464    }
465
466    // --- ctrl_to_arrow tests ---
467
468    fn ctrl_ev(ch: char) -> KeyEvent {
469        KeyEvent::new(
470            Key::Char(ch),
471            KeyModifiers {
472                ctrl: true,
473                ..Default::default()
474            },
475        )
476    }
477
478    #[test]
479    fn ctrl_to_arrow_s_maps_to_left_with_cleared_modifiers() {
480        let result = ctrl_to_arrow(ctrl_ev('s'));
481        assert_eq!(result.key, Key::Left);
482        assert_eq!(result.modifiers, KeyModifiers::default());
483    }
484
485    #[test]
486    fn ctrl_to_arrow_uppercase_s_also_maps_to_left() {
487        let result = ctrl_to_arrow(ctrl_ev('S'));
488        assert_eq!(result.key, Key::Left);
489        assert_eq!(result.modifiers, KeyModifiers::default());
490    }
491
492    #[test]
493    fn ctrl_to_arrow_h_maps_to_backspace() {
494        let result = ctrl_to_arrow(ctrl_ev('h'));
495        assert_eq!(result.key, Key::Backspace);
496        assert_eq!(result.modifiers, KeyModifiers::default());
497    }
498
499    #[test]
500    fn ctrl_to_arrow_r_maps_to_pageup() {
501        let result = ctrl_to_arrow(ctrl_ev('r'));
502        assert_eq!(result.key, Key::PageUp);
503        assert_eq!(result.modifiers, KeyModifiers::default());
504    }
505
506    #[test]
507    fn ctrl_to_arrow_d_maps_to_right() {
508        let result = ctrl_to_arrow(ctrl_ev('d'));
509        assert_eq!(result.key, Key::Right);
510        assert_eq!(result.modifiers, KeyModifiers::default());
511    }
512
513    #[test]
514    fn ctrl_to_arrow_literal_left_without_ctrl_passes_through() {
515        let ke = KeyEvent::from(Key::Left);
516        assert_eq!(ctrl_to_arrow(ke), ke);
517    }
518
519    #[test]
520    fn ctrl_to_arrow_left_with_ctrl_passes_through() {
521        // A literal arrow key with ctrl held is NOT a Char — must pass through.
522        let ke = KeyEvent::new(
523            Key::Left,
524            KeyModifiers {
525                ctrl: true,
526                ..Default::default()
527            },
528        );
529        assert_eq!(ctrl_to_arrow(ke), ke);
530    }
531
532    #[test]
533    fn ctrl_to_arrow_char_s_without_ctrl_passes_through() {
534        let ke = KeyEvent::from(Key::Char('s'));
535        assert_eq!(ctrl_to_arrow(ke), ke);
536    }
537
538    #[test]
539    fn ctrl_to_arrow_remaining_seven_mappings() {
540        // Table-driven coverage for the 7 mappings not exercised by the tests above.
541        let cases: &[(char, Key)] = &[
542            ('e', Key::Up),
543            ('x', Key::Down),
544            ('a', Key::Home),
545            ('f', Key::End),
546            ('g', Key::Delete),
547            ('v', Key::Insert),
548            ('c', Key::PageDown),
549        ];
550        for &(ch, expected_key) in cases {
551            let result = ctrl_to_arrow(ctrl_ev(ch));
552            assert_eq!(
553                result.key,
554                expected_key,
555                "Ctrl+{} should map to {:?}",
556                ch.to_ascii_uppercase(),
557                expected_key
558            );
559            assert_eq!(
560                result.modifiers,
561                KeyModifiers::default(),
562                "Ctrl+{} mapping should clear all modifiers",
563                ch.to_ascii_uppercase()
564            );
565        }
566    }
567
568    #[test]
569    fn ctrl_to_arrow_unmapped_ctrl_letter_passes_through() {
570        // Ctrl+'z' is not in the table; the event must be returned unchanged.
571        let ke = ctrl_ev('z');
572        let result = ctrl_to_arrow(ke);
573        assert_eq!(result.key, Key::Char('z'), "key must remain Char('z')");
574        assert!(result.modifiers.ctrl, "ctrl flag must still be set");
575        assert_eq!(result, ke, "entire event must be unchanged");
576    }
577
578    // --- is_alt_hotkey tests ---
579
580    #[test]
581    fn is_alt_hotkey_alt_lower_matches_uppercase_hot() {
582        let ke = KeyEvent::new(
583            Key::Char('o'),
584            KeyModifiers {
585                alt: true,
586                ..Default::default()
587            },
588        );
589        assert!(is_alt_hotkey(&ke, 'O'));
590    }
591
592    #[test]
593    fn is_alt_hotkey_alt_shift_also_matches() {
594        let ke = KeyEvent::new(
595            Key::Char('o'),
596            KeyModifiers {
597                alt: true,
598                shift: true,
599                ..Default::default()
600            },
601        );
602        // Shift is not checked — alt+shift+o still matches hotkey 'O'.
603        assert!(is_alt_hotkey(&ke, 'O'));
604    }
605
606    #[test]
607    fn is_alt_hotkey_no_alt_returns_false() {
608        let ke = KeyEvent::from(Key::Char('o'));
609        assert!(!is_alt_hotkey(&ke, 'O'));
610    }
611
612    #[test]
613    fn is_alt_hotkey_wrong_char_returns_false() {
614        let ke = KeyEvent::new(
615            Key::Char('x'),
616            KeyModifiers {
617                alt: true,
618                ..Default::default()
619            },
620        );
621        assert!(!is_alt_hotkey(&ke, 'O'));
622    }
623
624    // --- is_plain_hotkey tests ---
625
626    #[test]
627    fn is_plain_hotkey_matches_case_insensitively() {
628        let ke = KeyEvent::from(Key::Char('o'));
629        assert!(is_plain_hotkey(&ke, 'O'));
630    }
631
632    #[test]
633    fn is_plain_hotkey_wrong_char_returns_false() {
634        let ke = KeyEvent::from(Key::Char('x'));
635        assert!(!is_plain_hotkey(&ke, 'O'));
636    }
637
638    #[test]
639    fn is_plain_hotkey_ctrl_held_returns_false() {
640        // A plain hotkey must be unmodified: Ctrl+O is not a plain 'O' press.
641        let ke = KeyEvent::new(
642            Key::Char('o'),
643            KeyModifiers {
644                ctrl: true,
645                ..Default::default()
646            },
647        );
648        assert!(!is_plain_hotkey(&ke, 'O'));
649    }
650
651    #[test]
652    fn is_plain_hotkey_alt_held_returns_false() {
653        // Under Alt this is not a plain press; the Alt match is is_alt_hotkey's job.
654        let ke = KeyEvent::new(
655            Key::Char('o'),
656            KeyModifiers {
657                alt: true,
658                ..Default::default()
659            },
660        );
661        assert!(!is_plain_hotkey(&ke, 'O'));
662    }
663}