diff options
author | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-15 16:48:12 +0800 |
---|---|---|
committer | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-15 16:48:12 +0800 |
commit | 86e593f0baee79a973845e4c7dae1339d3e838df (patch) | |
tree | b2b998d630b35963ac0921fe61d4e7cbacb320a3 /src | |
parent | 08dfbb633fe25cc922b898aaf367f26a08730d91 (diff) |
pane is now displayed during deletion; keeps last item selected
Diffstat (limited to 'src')
-rw-r--r-- | src/interactive/app/handlers.rs | 15 | ||||
-rw-r--r-- | src/interactive/widgets/mark.rs | 22 |
2 files changed, 25 insertions, 12 deletions
diff --git a/src/interactive/app/handlers.rs b/src/interactive/app/handlers.rs index 7733075..cfbcb14 100644 --- a/src/interactive/app/handlers.rs +++ b/src/interactive/app/handlers.rs @@ -222,10 +222,17 @@ impl TerminalApp { let res = self.window.mark_pane.take().and_then(|p| p.key(key)); self.window.mark_pane = match res { Some((pane, mode)) => match mode { - Some(MarkMode::Delete) => pane.iterate_deletable_items(|entry_to_delete| { - self.draw(terminal).ok(); - self.delete_entry(entry_to_delete) - }), + Some(MarkMode::Delete) => { + pane.iterate_deletable_items(|mut pane, entry_to_delete| { + self.window.mark_pane = Some(pane); + self.draw(terminal).ok(); + pane = self.window.mark_pane.take().expect("option to be filled"); + match self.delete_entry(entry_to_delete) { + Ok(_) => Ok(pane), + Err(c) => Err((pane, c)), + } + }) + } None => Some(pane), }, None => None, diff --git a/src/interactive/widgets/mark.rs b/src/interactive/widgets/mark.rs index e10930d..cbd34a6 100644 --- a/src/interactive/widgets/mark.rs +++ b/src/interactive/widgets/mark.rs @@ -105,16 +105,22 @@ impl MarkPane { pub fn iterate_deletable_items( mut self, - mut delete_fn: impl FnMut(TreeIndex) -> Result<(), usize>, + mut delete_fn: impl FnMut(Self, TreeIndex) -> Result<Self, (Self, usize)>, ) -> Option<Self> { loop { match self.next_entry_for_deletion() { - Some(entry_to_delete) => match delete_fn(entry_to_delete) { - Ok(_) => match self.delete_entry() { - Some(p) => self = p, - None => return None, - }, - Err(num_errors) => self.set_error_on_marked_item(num_errors), + Some(entry_to_delete) => match delete_fn(self, entry_to_delete) { + Ok(pane) => { + self = pane; + match self.delete_entry() { + Some(p) => self = p, + None => return None, + } + } + Err((pane, num_errors)) => { + self = pane; + self.set_error_on_marked_item(num_errors) + } }, None => return Some(self), } @@ -131,7 +137,7 @@ impl MarkPane { _ => { self.selected = match position + 1 { p if p < self.marked.len() => Some(p), - _ => None, + _ => Some(self.marked.len().saturating_sub(1)), }; self.tree_index_by_list_position(position + 1) } |