pub struct FilterState {
pub active: bool,
/* private fields */
}Expand description
Inline fuzzy-filter state machine + memoised matched-indices cache.
Default opens the filter in the closed / empty / cold-cache state.
Fields§
§active: booltrue while the user is typing in the / bar. Toggles by
Self::open / Self::close_keep / Self::close_cancel
(the close methods describe the sticky-vs-clear contract).
Implementations§
Source§impl FilterState
impl FilterState
pub fn new() -> Self
Sourcepub fn query(&self) -> &str
pub fn query(&self) -> &str
Read access to the live query buffer. Returned as &str so the
caller can’t grow / shrink the underlying String and bypass the
cache-invalidation contract on push_char / pop_char /
set_query / clear. Use query().len() if you need the byte
length and query().is_empty() for the “no filter” check.
Sourcepub fn push_char(&mut self, c: char)
pub fn push_char(&mut self, c: char)
Append a character to the query buffer and invalidate the cache.
Called by the event loop on every keypress while active.
Sourcepub fn pop_char(&mut self)
pub fn pop_char(&mut self)
Pop the last character off the query buffer. Backspace handler.
No-op on an empty buffer (the user already cleared the filter;
the second backspace must not toggle active off — Esc does
that). Invalidates the cache iff a character actually came off.
Sourcepub fn set_query(&mut self, q: String)
pub fn set_query(&mut self, q: String)
Overwrite the query buffer wholesale. Invalidates the cache. Used by tests and by any future caller that wants to set the filter programmatically (e.g. a “restore session” path).
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clear the buffer, close the bar, and invalidate the cache.
Used by Self::close_cancel and as a standalone reset.
Sourcepub fn open(&mut self)
pub fn open(&mut self)
Open the filter bar. Preserves the existing query so the user can
refine an already-sticky filter; close_cancel is how they start
fresh. Does NOT invalidate the cache: opening the bar doesn’t
change what’s filtered, only that the next keypress targets the
buffer.
Sourcepub fn close_keep(&mut self)
pub fn close_keep(&mut self)
Close the filter bar but keep the query — the sticky-filter path (Enter). Cache survives: the filter set didn’t change, only the input target. Subsequent reads stay cached.
Sourcepub fn close_cancel(&mut self)
pub fn close_cancel(&mut self)
Close the filter bar AND clear the query — the cancel path (Esc).
Delegates to clear so the cache invalidation contract stays in
one place.
Sourcepub fn invalidate(&mut self)
pub fn invalidate(&mut self)
Explicit cache flush. Called by App::refresh after it mutates
App.worktrees, so the next render recomputes against the fresh
list. (The cache_worktrees_len auto-invalidation catches len
changes too, but refresh may produce a vec of the same length
with different contents — clearing here is the safe play.)
Sourcepub fn filtered_indices<F>(
&mut self,
worktrees: &[WorktreeInfo],
compute: F,
) -> &[usize]
pub fn filtered_indices<F>( &mut self, worktrees: &[WorktreeInfo], compute: F, ) -> &[usize]
Memoised lookup of the matched-indices vec. On cold cache, runs
compute(&self.query, worktrees) and stores the result; on hot
cache (no buffer mutation since the previous call AND same
worktrees length), returns the cached slice directly.
Returns a borrowed slice so the call sites in tui/ui.rs don’t
pay for a clone on the hot path. The compute closure shape
matches fuzzy_match_indices — the App passes that fn in,
keeping FilterState agnostic of the matcher (and trivial to
unit-test with a counting closure).
Sourcepub fn snapshot_indices<F>(
&self,
worktrees: &[WorktreeInfo],
compute: F,
) -> Vec<usize>
pub fn snapshot_indices<F>( &self, worktrees: &[WorktreeInfo], compute: F, ) -> Vec<usize>
&self-friendly read for callers that already know the cache is
warm (or are willing to recompute via compute without storing).
Used by App::selected() which is &self for ergonomics — most
callers of selected hold a shared borrow and can’t take the
&mut needed by Self::filtered_indices. Returns an owned
Vec<usize> because the caller may hit the recompute branch and
we can’t surface a temporary as &[usize]. Cheap when the cache
is hot (the per-frame render already populated it); equivalent to
the pre-extraction cost when cold.
Trait Implementations§
Source§impl Debug for FilterState
impl Debug for FilterState
Source§impl Default for FilterState
impl Default for FilterState
Source§fn default() -> FilterState
fn default() -> FilterState
Auto Trait Implementations§
impl Freeze for FilterState
impl RefUnwindSafe for FilterState
impl Send for FilterState
impl Sync for FilterState
impl Unpin for FilterState
impl UnsafeUnpin for FilterState
impl UnwindSafe for FilterState
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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