on master help sign in
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.

commit2ce87968cd5983167271cd306ab1c1d72a9c488d authorBlaž Hrastnik <blaz@mxxn.io> dateWed 8 Sep 2021, 14:19 (5 years ago) parentf871d31
1 file changed+7−3
helix-term/src/ui/picker.rs+7−3
helix-term/src/ui/picker.rs+7−3
@@ -124,9 +124,13 @@ impl<T: 'static> Component for FilePicker<T> {
124124 }) {
125125 // align to middle
126126 let first_line = line
127− .map(|(start, _)| start)
128− .unwrap_or(0)
129− .saturating_sub(inner.height as usize / 2);
127+ .map(|(start, end)| {
128+ let height = end.saturating_sub(start) + 1;
129+ let middle = start + (height.saturating_sub(1) / 2);
130+ middle.saturating_sub(inner.height as usize / 2).min(start)
131+ })
132+ .unwrap_or(0);
133+
130134 let offset = Position::new(first_line, 0);
131135
132136 let highlights = EditorView::doc_syntax_highlights(