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: boolWhether search mode is active
query: StringCurrent search query
results: Vec<R>Search results
selected: usizeSelected result index
Implementations§
Source§impl<R> SearchState<R>
impl<R> SearchState<R>
Sourcepub fn has_valid_query(&self) -> bool
pub fn has_valid_query(&self) -> bool
Check if the query is long enough to search.
Sourcepub fn query_lower(&self) -> String
pub fn query_lower(&self) -> String
Get the lowercased query for case-insensitive matching.
Sourcepub fn set_results(&mut self, results: Vec<R>)
pub fn set_results(&mut self, results: Vec<R>)
Set results and reset selection.
Sourcepub fn selected_result(&self) -> Option<&R>
pub fn selected_result(&self) -> Option<&R>
Get the currently selected result.
Sourcepub fn select_next(&mut self)
pub fn select_next(&mut self)
Select the next result.
Sourcepub const fn select_prev(&mut self)
pub const fn select_prev(&mut self)
Select the previous result.
Sourcepub fn has_results(&self) -> bool
pub fn has_results(&self) -> bool
Check if there are any results.
Sourcepub fn result_count(&self) -> usize
pub fn result_count(&self) -> usize
Get the result count.
Trait Implementations§
Source§impl<R: Clone> Clone for SearchState<R>
impl<R: Clone> Clone for SearchState<R>
Source§fn clone(&self) -> SearchState<R>
fn clone(&self) -> SearchState<R>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<R: Debug> Debug for SearchState<R>
impl<R: Debug> Debug for SearchState<R>
Source§impl<R> Default for SearchState<R>
impl<R> Default for SearchState<R>
Source§fn set_selected(&mut self, idx: usize)
fn set_selected(&mut self, idx: usize)
Set the selection index.
Source§fn select_next(&mut self)
fn select_next(&mut self)
Move selection to the next item.
Source§fn select_prev(&mut self)
fn select_prev(&mut self)
Move selection to the previous item.
Source§fn clamp_selection(&mut self)
fn clamp_selection(&mut self)
Ensure selection is within valid bounds.
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> 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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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 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>
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