Skip to content

Commit

Permalink
ui: Be smarter about centering previews
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
archseer committed Sep 8, 2021
1 parent f871d31 commit 2ce8796
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions helix-term/src/ui/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 2ce8796

Please sign in to comment.