diff options
author | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-08 04:42:17 +0530 |
---|---|---|
committer | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-08 05:05:13 +0530 |
commit | b4669c0214a1bc858cf437a65583af7e4b9ec277 (patch) | |
tree | 0b80c18f06724469f76b6e6e2bb716833f63b803 /src/interactive/widgets/mark.rs | |
parent | fcde45752a9b86ed606b78f522f6b6dd0de25457 (diff) |
Pune/India: Rustic way of handling the mark panes disappearance
Interesting: before that fix, the GUI was in an invalid state,
as the mark pane disappeared without setting the focus back to the
main window.
Thanks to everything being encoded in the typesystem and no assumptions
made, the program wouldn't crash when buttons are pressed, which would
otherwise be attempted to dispatch to the now gone mark pane.
Instead one could press 'q' or tab, as fortunately, the pane
handling is always done before any of the panes get a chance.
Diffstat (limited to 'src/interactive/widgets/mark.rs')
-rw-r--r-- | src/interactive/widgets/mark.rs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/interactive/widgets/mark.rs b/src/interactive/widgets/mark.rs index cc6bf88..5f0255d 100644 --- a/src/interactive/widgets/mark.rs +++ b/src/interactive/widgets/mark.rs @@ -82,18 +82,19 @@ impl MarkPane { pub fn marked(&self) -> &EntryMarkMap { &self.marked } - pub fn key(&mut self, key: Key) { + pub fn key(mut self, key: Key) -> Option<Self> { match key { - Char('d') | Char(' ') => self.remove_selected_and_move_down(), + Char('d') | Char(' ') => return self.remove_selected_and_move_down(), Ctrl('u') | PageUp => self.change_selection(CursorDirection::PageUp), Char('k') | Up => self.change_selection(CursorDirection::Up), Char('j') | Down => self.change_selection(CursorDirection::Down), Ctrl('d') | PageDown => self.change_selection(CursorDirection::PageDown), _ => {} }; + Some(self) } - fn remove_selected_and_move_down(&mut self) { + fn remove_selected_and_move_down(mut self) -> Option<Self> { if let Some(selected) = self.selected { let (idx, se_len) = { let sorted_entries: Vec<_> = self @@ -108,10 +109,14 @@ impl MarkPane { }; if let Some(idx) = idx { self.marked.remove(&idx); - if selected == se_len.saturating_sub(1) { - self.selected = selected.checked_sub(1); + if se_len.saturating_sub(1) == 0 { + return None; } + self.selected = selected.checked_sub(1); } + Some(self) + } else { + Some(self) } } @@ -208,7 +213,7 @@ impl MarkPane { let inner_area = block.inner(area); block.draw(area, buf); - let list_area = if self.has_focus && !self.marked.is_empty() { + let list_area = if self.has_focus { let (help_line_area, list_area) = { let regions = Layout::default() .direction(Direction::Vertical) |