Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiel committed Jun 6, 2019
1 parent b79b1ae commit 4cde0f6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
27 changes: 14 additions & 13 deletions src/interactive/app/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ pub enum CursorDirection {
PageUp,
}

impl CursorDirection {
pub fn move_cursor(&self, n: usize) -> usize {
use CursorDirection::*;
match self {
Down => n.saturating_add(1),
Up => n.saturating_sub(1),
PageDown => n.saturating_add(10),
PageUp => n.saturating_sub(10),
}
}
}

impl TerminalApp {
pub fn cycle_focus(&mut self) {
use FocussedPane::*;
Expand Down Expand Up @@ -90,14 +102,8 @@ impl TerminalApp {
}

pub fn scroll_help(&mut self, direction: CursorDirection) {
use CursorDirection::*;
if let Some(ref mut pane) = self.window.help_pane {
pane.scroll = match direction {
Down => pane.scroll.saturating_add(1),
Up => pane.scroll.saturating_sub(1),
PageDown => pane.scroll.saturating_add(10),
PageUp => pane.scroll.saturating_sub(10),
};
pane.scroll = direction.move_cursor(pane.scroll as usize) as u16;
}
}

Expand All @@ -107,12 +113,7 @@ impl TerminalApp {
Some(ref selected) => entries
.iter()
.find_position(|b| b.index == *selected)
.map(|(idx, _)| match direction {
CursorDirection::PageDown => idx.saturating_add(10),
CursorDirection::Down => idx.saturating_add(1),
CursorDirection::Up => idx.saturating_sub(1),
CursorDirection::PageUp => idx.saturating_sub(10),
})
.map(|(idx, _)| direction.move_cursor(idx))
.unwrap_or(0),
None => 0,
};
Expand Down
1 change: 0 additions & 1 deletion src/interactive/widgets/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ impl MainWindow {
if let Some((mark_area, pane)) = mark_pane {
let props = MarkPaneProps {
border_style: mark_style,
selected: None,
marked: &state.marked,
};
pane.render(props, mark_area, buf);
Expand Down
5 changes: 2 additions & 3 deletions src/interactive/widgets/mark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use tui_react::{List, ListProps};
#[derive(Default)]
pub struct MarkPane {
pub list: List,
pub selected: Option<TreeIndex>,
}

pub struct MarkPaneProps<'a> {
pub border_style: Style,
pub selected: Option<TreeIndex>,
pub marked: &'a EntryMarkMap,
}

Expand All @@ -28,15 +28,14 @@ impl MarkPane {
) {
let MarkPaneProps {
border_style,
selected,
marked,
} = props.borrow();

let block = Block::default()
.title("Marked Entries")
.border_style(*border_style)
.borders(Borders::ALL);
let entry_in_view = selected.and_then(|idx| {
let entry_in_view = self.selected.and_then(|idx| {
marked
.iter()
.enumerate()
Expand Down

0 comments on commit 4cde0f6

Please sign in to comment.