diff options
author | Blaž Hrastnik | 2021-09-08 05:19:25 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-09-08 05:19:25 +0000 |
commit | 2ce87968cd5983167271cd306ab1c1d72a9c488d (patch) | |
tree | df3bb85b43dbcfead4eb79a92018c84f6802b124 /helix-term/src/ui | |
parent | f871d318c00023416dbc21747fd227f4a24c94c6 (diff) |
ui: Be smarter about centering previews
Try centering the whole block. If the block is too big for the viewport,
then make sure that the first line is within the preview.
Diffstat (limited to 'helix-term/src/ui')
-rw-r--r-- | helix-term/src/ui/picker.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 06e424ea..e040e0ff 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -124,9 +124,13 @@ impl<T: 'static> Component for FilePicker<T> { }) { // align to middle let first_line = line - .map(|(start, _)| start) - .unwrap_or(0) - .saturating_sub(inner.height as usize / 2); + .map(|(start, end)| { + let height = end.saturating_sub(start) + 1; + let middle = start + (height.saturating_sub(1) / 2); + middle.saturating_sub(inner.height as usize / 2).min(start) + }) + .unwrap_or(0); + let offset = Position::new(first_line, 0); let highlights = EditorView::doc_syntax_highlights( |