Skip to main content

SearchState

Struct SearchState 

Source
pub struct SearchState<R> {
    pub active: bool,
    pub query: String,
    pub results: Vec<R>,
    pub selected: usize,
}
Expand description

Generic search state that works with any result type.

This replaces the duplicate DiffSearchState and SearchState structs with a single, type-parameterized implementation.

§Type Parameter

  • R: The result type for search matches (e.g., DiffSearchResult, SearchResult)

§Example

use crate::tui::viewmodel::SearchState;

// For diff mode
let mut search: SearchState<DiffSearchResult> = SearchState::new();

// For view mode
let mut search: SearchState<ViewSearchResult> = SearchState::new();

Fields§

§active: bool

Whether search mode is active

§query: String

Current search query

§results: Vec<R>

Search results

§selected: usize

Selected result index

Implementations§

Source§

impl<R> SearchState<R>

Source

pub const fn new() -> Self

Create a new empty search state.

Source

pub fn start(&mut self)

Start search mode.

Source

pub const fn stop(&mut self)

Stop search mode.

Source

pub fn clear(&mut self)

Clear query and results.

Source

pub fn push_char(&mut self, c: char)

Add a character to the query.

Source

pub fn pop_char(&mut self)

Remove the last character from the query.

Source

pub fn has_valid_query(&self) -> bool

Check if the query is long enough to search.

Source

pub fn query_lower(&self) -> String

Get the lowercased query for case-insensitive matching.

Source

pub fn set_results(&mut self, results: Vec<R>)

Set results and reset selection.

Source

pub fn selected_result(&self) -> Option<&R>

Get the currently selected result.

Source

pub fn select_next(&mut self)

Select the next result.

Source

pub const fn select_prev(&mut self)

Select the previous result.

Source

pub fn has_results(&self) -> bool

Check if there are any results.

Source

pub fn result_count(&self) -> usize

Get the result count.

Trait Implementations§

Source§

impl<R: Clone> Clone for SearchState<R>

Source§

fn clone(&self) -> SearchState<R>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<R: Debug> Debug for SearchState<R>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<R> Default for SearchState<R>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<R> ListNavigation for SearchState<R>

Source§

fn selected(&self) -> usize

Get the current selection index.
Source§

fn set_selected(&mut self, idx: usize)

Set the selection index.
Source§

fn total(&self) -> usize

Get the total number of items.
Source§

fn set_total(&mut self, _total: usize)

Set the total number of items.
Source§

fn select_next(&mut self)

Move selection to the next item.
Source§

fn select_prev(&mut self)

Move selection to the previous item.
Source§

fn clamp_selection(&mut self)

Ensure selection is within valid bounds.
Source§

fn page_up(&mut self)

Move selection up by a page.
Source§

fn page_down(&mut self)

Move selection down by a page.
Source§

fn go_first(&mut self)

Move to the first item.
Source§

fn go_last(&mut self)

Move to the last item.

Auto Trait Implementations§

§

impl<R> Freeze for SearchState<R>

§

impl<R> RefUnwindSafe for SearchState<R>
where R: RefUnwindSafe,

§

impl<R> Send for SearchState<R>
where R: Send,

§

impl<R> Sync for SearchState<R>
where R: Sync,

§

impl<R> Unpin for SearchState<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for SearchState<R>

§

impl<R> UnwindSafe for SearchState<R>
where R: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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