refactor: Improve filter naming

This commit is contained in:
Liam 2024-08-21 09:48:14 -07:00
parent 388c073116
commit 4e8cc2bc5c
No known key found for this signature in database
2 changed files with 7 additions and 7 deletions

View File

@ -16,14 +16,14 @@ pub enum SearchAction {
Update, Update,
} }
pub struct FilterInstance { pub struct Filter {
search_input: Vec<char>, search_input: Vec<char>,
in_search_mode: bool, in_search_mode: bool,
input_position: usize, input_position: usize,
items: Vec<ListEntry>, items: Vec<ListEntry>,
} }
impl FilterInstance { impl Filter {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
search_input: vec![], search_input: vec![],
@ -78,7 +78,7 @@ impl FilterInstance {
self.items.sort_by(|a, b| a.node.name.cmp(&b.node.name)); self.items.sort_by(|a, b| a.node.name.cmp(&b.node.name));
} }
} }
pub fn draw(&self, frame: &mut Frame, area: Rect, theme: &Theme) { pub fn draw_searchbar(&self, frame: &mut Frame, area: Rect, theme: &Theme) {
//Set the search bar text (If empty use the placeholder) //Set the search bar text (If empty use the placeholder)
let display_text = if !self.in_search_mode && self.search_input.is_empty() { let display_text = if !self.in_search_mode && self.search_input.is_empty() {
Span::raw("Press / to search") Span::raw("Press / to search")

View File

@ -1,5 +1,5 @@
use crate::{ use crate::{
filter::{FilterInstance, SearchAction}, filter::{Filter, SearchAction},
float::{Float, FloatContent}, float::{Float, FloatContent},
floating_text::FloatingText, floating_text::FloatingText,
running_command::{Command, RunningCommand}, running_command::{Command, RunningCommand},
@ -32,7 +32,7 @@ pub struct AppState {
/// This is the state asociated with the list widget, used to display the selection in the /// This is the state asociated with the list widget, used to display the selection in the
/// widget /// widget
selection: ListState, selection: ListState,
filter: FilterInstance, filter: Filter,
} }
pub enum Focus { pub enum Focus {
@ -59,7 +59,7 @@ impl AppState {
current_tab: ListState::default().with_selected(Some(0)), current_tab: ListState::default().with_selected(Some(0)),
visit_stack: vec![root_id], visit_stack: vec![root_id],
selection: ListState::default().with_selected(Some(0)), selection: ListState::default().with_selected(Some(0)),
filter: FilterInstance::new(), filter: Filter::new(),
}; };
state.update_items(); state.update_items();
state state
@ -107,7 +107,7 @@ impl AppState {
.constraints([Constraint::Length(3), Constraint::Min(1)].as_ref()) .constraints([Constraint::Length(3), Constraint::Min(1)].as_ref())
.split(horizontal[1]); .split(horizontal[1]);
self.filter.draw(frame, chunks[0], &self.theme); self.filter.draw_searchbar(frame, chunks[0], &self.theme);
let mut items: Vec<Line> = Vec::new(); let mut items: Vec<Line> = Vec::new();
if !self.at_root() { if !self.at_root() {