Skip to content

Commit

Permalink
Know about focus in marker pane
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiel committed Jun 6, 2019
1 parent beed74a commit 2dafff4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/interactive/app/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,24 @@ impl CursorDirection {
impl TerminalApp {
pub fn cycle_focus(&mut self) {
use FocussedPane::*;
self.window.mark_pane.as_mut().map(|p| p.set_focus(false));
self.state.focussed = match (
self.state.focussed,
&self.window.help_pane,
&self.window.mark_pane,
&mut self.window.mark_pane,
) {
(Main, Some(_), _) => Help,
(Help, _, Some(_)) => Mark,
(Help, _, Some(ref mut pane)) => {
pane.set_focus(true);
Mark
}
(Help, _, None) => Main,
(Mark, _, _) => Main,
(Main, None, None) => Main,
(Main, None, Some(_)) => Mark,
(Main, None, Some(ref mut pane)) => {
pane.set_focus(true);
Mark
}
};
}

Expand Down
10 changes: 10 additions & 0 deletions src/interactive/widgets/mark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,24 @@ pub struct MarkPane {
selected: Option<usize>,
marked: EntryMarkMap,
list: List,
has_focus: bool,
}

pub struct MarkPaneProps {
pub border_style: Style,
}

impl MarkPane {
pub fn set_focus(&mut self, has_focus: bool) {
self.has_focus = has_focus;
if has_focus {
self.selected = Some(self.marked.len().saturating_sub(1));
} else {
self.selected = None
}
}
pub fn toggle_index(mut self, index: TreeIndex, tree: &Tree) -> Option<Self> {
// TODO: use HashMapEntry (Vacant/Occupied)
if self.marked.get(&index).is_some() {
self.marked.remove(&index);
} else {
Expand Down

0 comments on commit 2dafff4

Please sign in to comment.