Skip to content

Commit

Permalink
Adjust finder status line for matches in header row
Browse files Browse the repository at this point in the history
  • Loading branch information
YS-L committed Dec 15, 2024
1 parent c523bfa commit f9f062b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
25 changes: 12 additions & 13 deletions src/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pub enum RowPos {

#[derive(Debug, Clone)]
pub struct FinderCursor {
row: RowPos,
column: usize,
pub row: RowPos,
pub column: usize,
}

impl FinderCursor {
Expand Down Expand Up @@ -94,7 +94,7 @@ impl FinderCursor {
pub struct Finder {
internal: Arc<Mutex<FinderInternalState>>,
pub cursor: Option<FinderCursor>,
pub row_hint: RowPos,
row_hint: RowPos,
target: Regex,
column_index: Option<usize>,
sorter: Option<Arc<sort::Sorter>>,
Expand Down Expand Up @@ -239,27 +239,26 @@ impl Finder {
(self.internal.lock().unwrap()).count
}

pub fn count_and_max_row_index(&self) -> (usize, Option<u64>) {
let g = self.internal.lock().unwrap();
(g.count, g.founds.last().map(|x| x.row_index() as u64))
}

pub fn found_any(&self) -> bool {
let g = self.internal.lock().unwrap();
g.count > 0 || g.found_header.is_some()
}

pub fn count_and_max_row_index(&self) -> (usize, Option<u64>) {
let g = self.internal.lock().unwrap();
(g.count, g.founds.last().map(|x| x.row_index() as u64))
pub fn header_has_match(&self) -> bool {
(self.internal.lock().unwrap()).found_header.is_some()
}

pub fn done(&self) -> bool {
(self.internal.lock().unwrap()).done
}

pub fn cursor(&self) -> Option<usize> {
if let Some(cursor) = &self.cursor {
if let RowPos::Row(row) = cursor.row {
return Some(row);
}
}
None
pub fn cursor(&self) -> Option<FinderCursor> {
self.cursor.as_ref().cloned()
}

pub fn cursor_row_order(&self) -> Option<usize> {
Expand Down
20 changes: 15 additions & 5 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,27 +925,31 @@ impl FinderState {
pub struct FinderActiveState {
find_complete: bool,
total_found: u64,
cursor_index: Option<u64>,
cursor: Option<find::FinderCursor>,
target: Regex,
column_index: Option<(usize, String)>,
found_record: Option<find::FoundEntry>,
selected_offset: Option<u64>,
is_filter: bool,
header_has_match: bool,
}

impl FinderActiveState {
pub fn new(finder: &find::Finder, rows_view: &view::RowsView) -> Self {
let header_has_match = finder.header_has_match();
let total_count = finder.count() + if header_has_match { 1 } else { 0 };
FinderActiveState {
find_complete: finder.done(),
total_found: finder.count() as u64,
cursor_index: finder.cursor().map(|x| x as u64),
total_found: total_count as u64,
cursor: finder.cursor(),
target: finder.target(),
column_index: finder
.column_index()
.map(|i| (i, rows_view.get_column_name_from_global_index(i))),
found_record: finder.current(),
selected_offset: rows_view.selected_offset(),
is_filter: rows_view.is_filter(),
header_has_match,
}
}

Expand All @@ -971,8 +975,14 @@ impl FinderActiveState {
} else {
cursor_str = "-".to_owned();
}
} else if let Some(i) = self.cursor_index {
cursor_str = (i.saturating_add(1)).to_string();
} else if let Some(cursor) = &self.cursor {
cursor_str = match cursor.row {
find::RowPos::Row(i) => (i
.saturating_add(1)
.saturating_add(if self.header_has_match { 1 } else { 0 }))
.to_string(),
find::RowPos::Header => "1".to_string(),
};
} else {
cursor_str = "-".to_owned();
}
Expand Down

0 comments on commit f9f062b

Please sign in to comment.