lattice_keymap/events.rs
1//! WK.4: typed events about chords.
2//!
3//! Declared here rather than in `lattice-host` because every field is a
4//! `lattice-keymap` or `lattice-protocol` type — the crate that owns the
5//! chord vocabulary is the honest home for an event about chords. The
6//! host publishes; which-key is one subscriber among possible future
7//! ones ("did you mean…", macro-recording HUDs, plugin observers).
8
9use lattice_protocol::KeyChord;
10
11use crate::{BindingMode, ModeId};
12
13/// Published on every keystroke whose outcome changes the pending-chord
14/// state: a prefix was entered, extended, resolved, or aborted.
15/// `chords` is empty when nothing is pending, which is the dismissal
16/// signal subscribers key off.
17///
18/// ## The payload rides on the event
19///
20/// It would be smaller to publish a bare "something changed" ping and
21/// have subscribers read the published render state — and it would be
22/// wrong. Tick callbacks run *before* the publish in both actor arms, so
23/// a subscriber reading published state would observe the PREVIOUS
24/// keystroke's prefix and arm one keystroke late. Carrying the payload
25/// makes that class of bug unrepresentable.
26///
27/// ## `pane_width`
28///
29/// Carried so the grid can be laid out in `lattice-keymap` (the width is
30/// known at build time), which keeps the popup's content ordinary buffer
31/// text: everything-is-a-buffer holds, no new render model crosses into
32/// either renderer, and the column algorithm is unit-testable with no
33/// renderer at all. The cost is that a resize while a popup is up leaves
34/// a stale grid, so subscribers dismiss on resize.
35#[derive(Debug, Clone, PartialEq, Eq)]
36pub struct PartialChordPending {
37 /// The chords pressed so far. Empty = nothing pending.
38 pub chords: Vec<KeyChord>,
39 /// The binding mode the next keystroke will resolve in.
40 pub binding_mode: BindingMode,
41 /// The active buffer's keymap-gated modes, in the order
42 /// `lookup_with_context` wants them (active major first, then minors
43 /// in activation order).
44 pub active_modes: Vec<ModeId>,
45 /// Text width of the pane the chord is pending in.
46 pub pane_width: u16,
47}
48
49lattice_protocol::register_event!(
50 PartialChordPending,
51 "keymap.partial-chord-pending",
52 "Fired when a multi-key chord is partway through (or has just \
53 resolved, with an empty chord list).",
54 "lattice-keymap",
55);