mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-24 18:36:18 +04:00
correctly center items in picker preview
This commit is contained in:
parent
e9d0bd7aef
commit
13d4463e41
@ -710,18 +710,30 @@ fn render_preview(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut offset = ViewPosition::default();
|
let mut offset = ViewPosition::default();
|
||||||
if let Some(range) = range {
|
if let Some((start_line, end_line)) = range {
|
||||||
let text_fmt = doc.text_format(inner.width, None);
|
let height = end_line - start_line;
|
||||||
let annotations = TextAnnotations::default();
|
let text = doc.text().slice(..);
|
||||||
(offset.anchor, offset.vertical_offset) = char_idx_at_visual_offset(
|
let start = text.line_to_char(start_line);
|
||||||
doc.text().slice(..),
|
let middle = text.line_to_char(start_line + height / 2);
|
||||||
doc.text().line_to_char(range.0),
|
if height < inner.height as usize {
|
||||||
// align to middle
|
let text_fmt = doc.text_format(inner.width, None);
|
||||||
-(inner.height as isize / 2),
|
let annotations = TextAnnotations::default();
|
||||||
0,
|
(offset.anchor, offset.vertical_offset) = char_idx_at_visual_offset(
|
||||||
&text_fmt,
|
text,
|
||||||
&annotations,
|
middle,
|
||||||
);
|
// align to middle
|
||||||
|
-(inner.height as isize / 2),
|
||||||
|
0,
|
||||||
|
&text_fmt,
|
||||||
|
&annotations,
|
||||||
|
);
|
||||||
|
if start < offset.anchor {
|
||||||
|
offset.anchor = start;
|
||||||
|
offset.vertical_offset = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
offset.anchor = start;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut highlights = EditorView::doc_syntax_highlights(
|
let mut highlights = EditorView::doc_syntax_highlights(
|
||||||
|
Loading…
Reference in New Issue
Block a user