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.
This commit is contained in:
parent
f871d318c0
commit
2ce87968cd
1 changed files with 7 additions and 3 deletions
|
@ -124,9 +124,13 @@ impl<T: 'static> Component for FilePicker<T> {
|
||||||
}) {
|
}) {
|
||||||
// align to middle
|
// align to middle
|
||||||
let first_line = line
|
let first_line = line
|
||||||
.map(|(start, _)| start)
|
.map(|(start, end)| {
|
||||||
.unwrap_or(0)
|
let height = end.saturating_sub(start) + 1;
|
||||||
.saturating_sub(inner.height as usize / 2);
|
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 offset = Position::new(first_line, 0);
|
||||||
|
|
||||||
let highlights = EditorView::doc_syntax_highlights(
|
let highlights = EditorView::doc_syntax_highlights(
|
||||||
|
|
Loading…
Reference in a new issue