mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-23 01:46:18 +04:00
Calculate offset when moving picker cursor
This commit is contained in:
parent
bcb1afeb4c
commit
aa8a8baeeb
@ -246,13 +246,14 @@ fn render(&self, area: Rect, surface: &mut Surface, cx: &mut Context) {
|
||||
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 @@ fn render(&self, area: Rect, surface: &mut Surface, cx: &mut Context) {
|
||||
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
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user