pub struct Filter { /* private fields */ }Expand description
The state behind a searchable list: the items, the ranked view of them, and which row of that view is active. Shared by every picker — the palette, the combobox — so the mapping below is written and tested once.
Implementations§
Source§impl Filter
impl Filter
pub fn new(items: Vec<SharedString>) -> Self
pub fn items(&self) -> &[SharedString]
Sourcepub fn filtered(&self) -> &[usize]
pub fn filtered(&self) -> &[usize]
The ranked view: indices into Self::items, in display order.
Sourcepub fn active(&self) -> Option<usize>
pub fn active(&self) -> Option<usize>
The highlighted row’s position in the FILTERED view — what a renderer compares each row against.
Sourcepub fn refilter(&mut self, query: &str)
pub fn refilter(&mut self, query: &str)
Re-rank against query, re-entering the list at the top: after
narrowing, the best match should be one Enter away.
pub fn step(&mut self, delta: isize)
Sourcepub fn set_active(&mut self, position: usize)
pub fn set_active(&mut self, position: usize)
Put the cursor on a position in the FILTERED view — what the mouse calls as it crosses a row, so a menu never shows a mouse cursor and a keyboard cursor at once.
Sourcepub fn active_item(&self) -> Option<usize>
pub fn active_item(&self) -> Option<usize>
The item confirming right now would pick — an index into
Self::items, never into the filtered view. Confusing the two is the
defining bug of a filtered list: it only appears once a query narrows
the rows, and then every selection picks the wrong thing.
Auto Trait Implementations§
impl Freeze for Filter
impl RefUnwindSafe for Filter
impl Send for Filter
impl Sync for Filter
impl Unpin for Filter
impl UnsafeUnpin for Filter
impl UnwindSafe for Filter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more