diff options
author | Canop <cano.petrole@gmail.com> | 2021-10-13 15:04:44 +0200 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2021-10-13 15:04:44 +0200 |
commit | f0f8d73a0ddc4a90b275595738670b6298125ff6 (patch) | |
tree | 824f5a45f9a1629c0feca05e0dce4f59ee97df59 /src | |
parent | 6c6d1a9b549431b945e1dc12289e1fb23cf36002 (diff) |
better make the selection visible
Diffstat (limited to 'src')
-rw-r--r-- | src/browser/browser_state.rs | 8 | ||||
-rw-r--r-- | src/tree/tree.rs | 14 |
2 files changed, 13 insertions, 9 deletions
diff --git a/src/browser/browser_state.rs b/src/browser/browser_state.rs index 34a19c5..6112e46 100644 --- a/src/browser/browser_state.rs +++ b/src/browser/browser_state.rs @@ -356,19 +356,19 @@ impl PanelState for BrowserState { CmdResult::Keep } Internal::previous_match => { - self.displayed_tree_mut().try_select_previous_match(); + self.displayed_tree_mut().try_select_previous_match(page_height); CmdResult::Keep } Internal::next_match => { - self.displayed_tree_mut().try_select_next_match(); + self.displayed_tree_mut().try_select_next_match(page_height); CmdResult::Keep } Internal::previous_same_depth => { - self.displayed_tree_mut().try_select_previous_same_depth(); + self.displayed_tree_mut().try_select_previous_same_depth(page_height); CmdResult::Keep } Internal::next_same_depth => { - self.displayed_tree_mut().try_select_next_same_depth(); + self.displayed_tree_mut().try_select_next_same_depth(page_height); CmdResult::Keep } Internal::page_down => { diff --git a/src/tree/tree.rs b/src/tree/tree.rs index b147490..4515bbb 100644 --- a/src/tree/tree.rs +++ b/src/tree/tree.rs @@ -270,7 +270,7 @@ impl Tree { pub fn make_selection_visible(&mut self, page_height: usize) { if page_height >= self.lines.len() || self.selection < 3 { self.scroll = 0; - } else if self.selection < self.scroll { + } else if self.selection <= self.scroll { self.scroll = self.selection - 2; } else if self.selection > self.lines.len() - 2 { self.scroll = self.lines.len() - page_height; @@ -339,7 +339,7 @@ impl Tree { } false } - pub fn try_select_previous_same_depth(&mut self) -> bool { + pub fn try_select_previous_same_depth(&mut self, page_height: usize) -> bool { let depth = self.lines[self.selection].depth; for di in (0..self.lines.len()).rev() { let idx = (self.selection + di) % self.lines.len(); @@ -348,11 +348,12 @@ impl Tree { continue; } self.selection = idx; + self.make_selection_visible(page_height); return true; } false } - pub fn try_select_next_same_depth(&mut self) -> bool { + pub fn try_select_next_same_depth(&mut self, page_height: usize) -> bool { let depth = self.lines[self.selection].depth; for di in 0..self.lines.len() { let idx = (self.selection + di + 1) % self.lines.len(); @@ -361,11 +362,12 @@ impl Tree { continue; } self.selection = idx; + self.make_selection_visible(page_height); return true; } false } - pub fn try_select_previous_match(&mut self) -> bool { + pub fn try_select_previous_match(&mut self, page_height: usize) -> bool { for di in (0..self.lines.len()).rev() { let idx = (self.selection + di) % self.lines.len(); let line = &self.lines[idx]; @@ -377,12 +379,13 @@ impl Tree { } if line.score > 0 { self.selection = idx; + self.make_selection_visible(page_height); return true; } } false } - pub fn try_select_next_match(&mut self) -> bool { + pub fn try_select_next_match(&mut self, page_height: usize) -> bool { for di in 0..self.lines.len() { let idx = (self.selection + di + 1) % self.lines.len(); let line = &self.lines[idx]; @@ -394,6 +397,7 @@ impl Tree { } if line.score > 0 { self.selection = idx; + self.make_selection_visible(page_height); return true; } } |