mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-25 06:57:31 -05:00
Fix selection after applying filters
This commit is contained in:
parent
b5fc06bd56
commit
1db5de9653
1 changed files with 14 additions and 4 deletions
|
@ -26,14 +26,16 @@ pub struct UiState<'a> {
|
|||
}
|
||||
|
||||
impl<'a> UiState<'a> {
|
||||
fn rows<'s, 'i>(
|
||||
fn rows<'s, 'c, 'i>(
|
||||
state_file: &'s StateFile,
|
||||
exercises: &'a [Exercise],
|
||||
rows_counter: &'c mut usize,
|
||||
filter: Filter,
|
||||
) -> impl Iterator<Item = Row<'a>> + 'i
|
||||
where
|
||||
's: 'i,
|
||||
'a: 'i,
|
||||
'c: 'i,
|
||||
{
|
||||
exercises
|
||||
.iter()
|
||||
|
@ -45,6 +47,8 @@ impl<'a> UiState<'a> {
|
|||
_ => (),
|
||||
}
|
||||
|
||||
*rows_counter += 1;
|
||||
|
||||
let next = if ind == state_file.next_exercise_ind() {
|
||||
">>>>".bold().red()
|
||||
} else {
|
||||
|
@ -67,8 +71,13 @@ impl<'a> UiState<'a> {
|
|||
}
|
||||
|
||||
pub fn with_updated_rows(mut self, state_file: &StateFile) -> Self {
|
||||
let rows = Self::rows(state_file, self.exercises, self.filter);
|
||||
let mut rows_counter = 0;
|
||||
let rows = Self::rows(state_file, self.exercises, &mut rows_counter, self.filter);
|
||||
self.table = self.table.rows(rows);
|
||||
|
||||
self.last_ind = rows_counter.saturating_sub(1);
|
||||
self.select(self.selected.min(self.last_ind));
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -89,7 +98,8 @@ impl<'a> UiState<'a> {
|
|||
];
|
||||
|
||||
let filter = Filter::None;
|
||||
let rows = Self::rows(state_file, exercises, filter);
|
||||
let mut rows_counter = 0;
|
||||
let rows = Self::rows(state_file, exercises, &mut rows_counter, filter);
|
||||
|
||||
let table = Table::new(rows, widths)
|
||||
.header(header)
|
||||
|
@ -111,7 +121,7 @@ impl<'a> UiState<'a> {
|
|||
exercises,
|
||||
selected,
|
||||
table_state,
|
||||
last_ind: exercises.len() - 1,
|
||||
last_ind: rows_counter.saturating_sub(1),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue