Expand description
Keys bound to commands, resolved by the framework alone (ADR 0007).
Bindings come in layers: the user’s over the workspace’s over the
framework’s defaults over the suggestions components make. Among the
bindings of the pressed keys whose when holds, the winner is the
greatest (depth, layer, specificity, order): the binding testing
keys set nearest the focus, then the higher layer, then the clause
testing more keys, then the last declared.
Two removals: a binding to Action::Remove ("-id" in files) takes
a command’s bindings away from the layers below, and Action::Unbind
(null in files) takes away every binding of exactly those keys from
the layers below. Keys are logical: what the key produces, so top-row
and keypad digits are the same. A shortcut is one or more chords
(Ctrl+K Ctrl+S).
A binding whose command went with its plugin is dormant
(Keymap::set_dormant, ADR 0028): it stays in its layer and is saved
with it, but it does not take its keys, which go to the next binding
of them; it shows no key and makes no conflict, a trace says
DORMANT, and Keymap::dormant lists it for a shortcuts editor.
It is live again as soon as its command is taken out of the set.
A chord’s key may also be a pointer gesture (Pointer): the wheel,
a smooth scroll, a pinch, a click, a double click or a drag of a
button, with the same modifiers (Ctrl+Wheel, MiddleDrag,
Shift+PrimaryDrag). Such a chord stands alone (never in a
sequence) and is bound in a canvas’s scope (surface:canvas.image);
the key dispatcher never sees it: the canvas asks the keymap
(Keymap::pointer_bindings) what its gestures do.
use egui_pop_model::ids::{CommandId, OwnerId};
use egui_pop_model::keymap::{Action, Keymap, Keys, Layer, Resolution};
use egui_pop_model::when::WhenContext;
let mut k = Keymap::new();
let fw = OwnerId::FRAMEWORK;
k.bind(&fw, Layer::Default, "Ctrl+K Ctrl+S", Action::run("keys.editor"), "").unwrap();
let cx = WhenContext::new();
assert_eq!(k.resolve(&Keys::parse("Ctrl+K").unwrap(), &cx), Resolution::Pending);
let (r, trace) = k.resolve_traced(&Keys::parse("Ctrl+K Ctrl+S").unwrap(), &cx);
assert_eq!(r, Resolution::Run(CommandId::from_static("keys.editor")));
assert_eq!(trace.candidates.len(), 1);Structs§
- Bind
Options - How a binding listens: its scope, whether it fires while typing, and whether a modal lets it through.
- Binding
- A binding as declared.
- Candidate
- One candidate in a trace.
- Chord
- One chord: modifiers and a logical key, or a pointer gesture
(
Chord::pointer). - DocBinding
- A binding as saved.
- Keymap
- The bindings, by layer.
- Keymap
Diff - What loading a keymap document changes, against what was there.
- Keymap
Doc - A user’s (or workspace’s) keymap as saved: the
keymapdocument. - Keys
- A key sequence: one or more chords.
- Trace
- How a key sequence was resolved: every binding considered and why.
Enums§
- Action
- What a binding does.
- Button
- A pointer button, by its logical role: the system swaps primary and secondary for a left hand, and the application never sees it.
- KeyScope
- Where a binding listens. Each window dispatches its own keys and
bubbles outwards: a surface holding the focus, then the window’s
focused panel, then the window, then the whole application
(
KeyScope::tier); a binding of a narrower scope wins over one of a wider scope on the same keys. - Layer
- Where a binding comes from; later variants win.
- Pointer
- The pointer part of a chord: what the pointer does while the chord’s modifiers are held.
- Resolution
- What a key sequence does in a context.
- Typing
- Whether a binding fires while a text input has the focus.
- Verdict
- Why a candidate binding did or did not win.
Constants§
- CONTEXT_
WIDGET_ KEYS - The context key naming the keys the focused widget reads itself, as
chord key names separated by spaces (
arrowleft arrowright home): set by the key dispatcher while such a widget has the focus. A global binding of one of them without Ctrl or Alt is left to the widget (Verdict::LeftToWidget), unless it firesalwaysor its clause tests this key itself. - DORMANT
- What a trace says of a binding whose command’s plugin is
disconnected: the
becauseof itsVerdict::Lost, whosetois the binding that got the keys (empty when none did). A verdict of its own comes with the next breaking release of this enum.
Functions§
- drop_
placeholder_ keys - Version 1 of the keymap document gave a command’s removal a
placeholder key (
Ctrl+Alt+Shift+F24); version 2 gives it none. - pointer_
chords - Version 3 of the keymap document lets a chord be a pointer gesture
(
Ctrl+Wheel,MiddleDrag); version 2 documents read the same.