diff options
author | Canop <cano.petrole@gmail.com> | 2021-02-14 18:27:26 +0100 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2021-02-14 18:27:26 +0100 |
commit | 0016efad0cfecc0386fa8e01403d89af3766912b (patch) | |
tree | d8fc63016c6da7dd5fec74bc7a7c1c6e8628eb69 /src/tree | |
parent | e9cb412e05511d662a856f724451791bc92cc065 (diff) |
:line_up_no_cycle and :line_down_no_cyle
May be mapped instead of :line_up and :line_down when you
don't want to cycle (ie arrive on top when you go down past
the end of the tree/list):
{
key: ctrl-u
internal: line_up_no_cycle
}
{
key: ctrl-j
internal: line_down_no_cycle
}
Diffstat (limited to 'src/tree')
-rw-r--r-- | src/tree/tree.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/tree/tree.rs b/src/tree/tree.rs index 0404c75..36f2b7b 100644 --- a/src/tree/tree.rs +++ b/src/tree/tree.rs @@ -145,17 +145,22 @@ impl Tree { /// select another line /// /// For example the following one if dy is 1. - pub fn move_selection(&mut self, dy: i32, page_height: i32) { + pub fn move_selection(&mut self, dy: i32, page_height: i32, cycle: bool) { // FIXME may not work well if dy is too big - let l = self.lines.len(); + let l = self.lines.len() as i32; loop { - self.selection = (self.selection + ((l as i32) + dy) as usize) % l; + if !cycle { + let s = dy + (self.selection as i32); + if s < 0 || s >= l { + break; + } + } + self.selection = (self.selection + (l + dy) as usize) % self.lines.len(); if self.lines[self.selection].is_selectable() { break; } } // we adjust the scroll - let l = l as i32; let sel = self.selection as i32; if l > page_height { if dy < 0 { |