Skip to main content

TransientSpec

Struct TransientSpec 

Source
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.

§footer: Option<String>

Implementations§

Source§

impl TransientSpec

Source

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.

Source

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.

Source

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.

Source

pub fn item_at(&self, index: usize) -> Option<&TransientItem>

The index-th selectable item, in the same order Self::selectable_count counts.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for TransientSpec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more