aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorKevin Sjöberg2021-06-06 08:41:21 +0000
committerBlaž Hrastnik2021-06-06 10:18:09 +0000
commitaa8a8baeeb06cd94ed6329c535483f30835ec426 (patch)
tree46af9d950f11c9333b6fec90f00def272ee9fca8 /helix-term
parentbcb1afeb4ca9d1764b2f1dba08f9772ac744c83a (diff)
Calculate offset when moving picker cursor
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/ui/picker.rs11
1 files changed, 8 insertions, 3 deletions
diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs
index c3592062..494753c5 100644
--- a/helix-term/src/ui/picker.rs
+++ b/helix-term/src/ui/picker.rs
@@ -246,13 +246,14 @@ impl<T: 'static> Component for Picker<T> {
let selected = Style::default().fg(Color::Rgb(255, 255, 255));
let rows = inner.height - 2; // -1 for search bar
+ let offset = self.cursor / (rows as usize) * (rows as usize);
- let files = self.matches.iter().map(|(index, _score)| {
+ let files = self.matches.iter().skip(offset).map(|(index, _score)| {
(index, self.options.get(*index).unwrap()) // get_unchecked
});
for (i, (_index, option)) in files.take(rows as usize).enumerate() {
- if i == self.cursor {
+ if i == (self.cursor - offset) {
surface.set_string(inner.x + 1, inner.y + 2 + i as u16, ">", selected);
}
@@ -261,7 +262,11 @@ impl<T: 'static> Component for Picker<T> {
inner.y + 2 + i as u16,
(self.format_fn)(option),
inner.width as usize - 1,
- if i == self.cursor { selected } else { style },
+ if i == (self.cursor - offset) {
+ selected
+ } else {
+ style
+ },
);
}
}