Fix edge cases when handling multiple selection

This commit is contained in:
Dheepak Krishnamurthy 2021-03-23 23:36:02 -06:00
parent 82718db2f9
commit b6945ec785
3 changed files with 13 additions and 9 deletions

View file

@ -180,7 +180,7 @@ impl TTApp {
tasks: Arc::new(Mutex::new(vec![])),
task_details: HashMap::new(),
marked: HashSet::new(),
current_selection: None,
current_selection: Some(0),
current_context_filter: "".to_string(),
current_context: "".to_string(),
command: LineBuffer::with_capacity(MAX_LINE),
@ -834,7 +834,18 @@ impl TTApp {
pub fn update_task_table_state(&mut self) {
self.task_table_state.select(self.current_selection);
for uuid in self.marked.clone() {
if self.task_by_uuid(uuid).is_none() {
self.marked.remove(&uuid);
}
}
if self.marked.is_empty() {
self.task_table_state.single_selection();
}
self.task_table_state.clear();
for uuid in &self.marked {
self.task_table_state.mark(self.task_index_by_uuid(*uuid))
}
@ -1651,10 +1662,6 @@ impl TTApp {
} else if input == self.keyconfig.select {
self.task_table_state.multiple_selection();
self.toggle_mark();
if self.marked.is_empty() {
self.task_table_state.single_selection();
self.task_table_state.clear();
}
} else if input == self.keyconfig.refresh {
self.update(true)?;
} else if input == self.keyconfig.go_to_bottom || input == Key::End {

View file

@ -79,9 +79,6 @@ fn tui_main(_config: &str) -> Result<(), Box<dyn Error>> {
let maybeapp = TTApp::new();
match maybeapp {
Ok(mut app) => {
app.task_report_next();
app.context_next();
loop {
terminal.draw(|mut frame| app.draw(&mut frame)).unwrap();

View file

@ -37,7 +37,7 @@ impl Default for TableState {
fn default() -> TableState {
TableState {
offset: 0,
current_selection: None,
current_selection: Some(0),
marked: HashSet::new(),
mode: TableMode::SingleSelection,
}