pub struct TransientSpec {
pub title: String,
pub groups: Vec<TransientGroup>,
pub preview: Option<Box<dyn Fn(&TransientState) -> String + Send + Sync>>,
pub footer: Option<String>,
}Expand description
Specification for a transient menu — the complete layout.
Stored behind an Arc in the Picker struct so clone is a ref-count
bump; the preview boxed closure stays alive across clones.
Fields§
§title: String§groups: Vec<TransientGroup>§preview: Option<Box<dyn Fn(&TransientState) -> String + Send + Sync>>Optional live command preview. Called every time a flag toggles or an argument changes; the returned string is rendered in the picker’s preview pane.
Implementations§
Source§impl TransientSpec
impl TransientSpec
Sourcepub fn selectable_count(&self) -> usize
pub fn selectable_count(&self) -> usize
How many items can be selected — every item in every group, counted in group order.
This is the number <C-n> / <C-p> wrap on, and the reason
they can no longer run off the end: it is derived from the spec
alone, so the host clamps on data it owns rather than on a
viewport height only the renderer knows. The previous shape
stored a raw scroll offset and grew it unbounded, leaving the
stored value tens of rows past anything renderable — pressing
<C-p> then did nothing visible until the overshoot was walked
back off.
Sourcepub fn row_count(&self) -> usize
pub fn row_count(&self) -> usize
Rows the group+item list occupies — per group one header, one row per item and one trailing blank separator. EXCLUDES preview/footer, which only exist in the popup layout.
Lives here rather than in each renderer because both peers need it and both had their own copy: undercounting the separator in both made every multi-group menu’s box too short and capped its scroll before the last rows.
Sourcepub fn row_of_item(&self, index: usize) -> Option<usize>
pub fn row_of_item(&self, index: usize) -> Option<usize>
Which row the index-th selectable item is painted on, in the
same row stream Self::row_count measures. None when
index is past the last item.
The mapping is what lets a renderer window on a selection: the host moves an item index, and each peer turns it into the scroll offset its own geometry needs.
Sourcepub fn item_at(&self, index: usize) -> Option<&TransientItem>
pub fn item_at(&self, index: usize) -> Option<&TransientItem>
The index-th selectable item, in the same order
Self::selectable_count counts.
Sourcepub fn resolve_key(&self, typed: &str) -> KeyResolution<'_>
pub fn resolve_key(&self, typed: &str) -> KeyResolution<'_>
What the keys typed so far mean at this level.
Transient keys are strings, not characters — magit binds
multi-key rows (, k delete, , r rename, = f set target)
and lattice follows it. The host used to compare one typed
char against them, so every multi-key row was unreachable by
keypress: it rendered, <C-n> reached it, <CR> fired it, and
its own key did nothing at all.
An exact match wins over a prefix. A key that both completes
one row and begins another is ambiguous, and vim resolves that
with timeoutlen — machinery this editor does not have (there
is no ambiguous-chord timeout anywhere; AbsorbPartialChord
waits indefinitely). Firing the exact match is the resolution
that never leaves a key hanging on a timer that does not exist.
No spec has such a pair today; this decides it if one appears.
Sourcepub fn item_matches_prefix(item: &TransientItem, typed: &str) -> bool
pub fn item_matches_prefix(item: &TransientItem, typed: &str) -> bool
True when item is still reachable by typing more after
typed — what the renderers dim on.
An empty typed matches everything, so a menu with no prefix
pending renders exactly as it always did.
Sourcepub fn scroll_for(&self, selected: usize, visible: usize) -> usize
pub fn scroll_for(&self, selected: usize, visible: usize) -> usize
The scroll offset that keeps selected’s row inside a window
visible rows tall, clamped so the list never scrolls past its
own end.
Derived fresh from the selection every frame rather than stored, which is what makes the overshoot unrepresentable: there is no scroll state left to drift out of range.