on master help sign in
Center the picker preview selection using visual lines (#7837)
a7a145aJesse Luehrs
helix-term/src/ui/picker.rs+15−15
@@ -27,7 +27,7 @@ use std::{collections::HashMap, io::Read, path::PathBuf};
27
27
28use crate::ui::{Prompt, PromptEvent};
28use crate::ui::{Prompt, PromptEvent};
29use helix_core::{
29use helix_core::{
30− movement::Direction, text_annotations::TextAnnotations,
30+ char_idx_at_visual_offset, movement::Direction, text_annotations::TextAnnotations,
31 unicode::segmentation::UnicodeSegmentation, Position, Syntax,
31 unicode::segmentation::UnicodeSegmentation, Position, Syntax,
32};
32};
33use helix_view::{
33use helix_view::{
@@ -690,20 +690,20 @@ impl<T: Item + 'static> Picker<T> {
690 }
690 }
691 };
691 };
692
692
693+ let mut offset = ViewPosition::default();
694+ if let Some(range) = range {
695+ let text_fmt = doc.text_format(inner.width, None);
696+ let annotations = TextAnnotations::default();
697+ (offset.anchor, offset.vertical_offset) = char_idx_at_visual_offset(
698+ doc.text().slice(..),
699+ doc.text().line_to_char(range.0),
693− // align to middle
700+ // align to middle
694− let first_line = range
695− .map(|(start, end)| {
696− let height = end.saturating_sub(start) + 1;
697− let middle = start + (height.saturating_sub(1) / 2);
698− middle.saturating_sub(inner.height as usize / 2).min(start)
701+ -(inner.height as isize / 2),
699− })
702+ 0,
700− .unwrap_or(0);
703+ &text_fmt,
701−
704+ &annotations,
702− let offset = ViewPosition {
705+ );
703− anchor: doc.text().line_to_char(first_line),
704− horizontal_offset: 0,
705− vertical_offset: 0,
706− };
706+ }
707
707
708 let mut highlights = EditorView::doc_syntax_highlights(
708 let mut highlights = EditorView::doc_syntax_highlights(
709 doc,
709 doc,