@@ -27,7 +27,7 @@ use std::{collections::HashMap, io::Read, path::PathBuf};
2727
2828use crate::ui::{Prompt, PromptEvent};
2929use helix_core::{
30− movement::Direction, text_annotations::TextAnnotations,
30+ char_idx_at_visual_offset, movement::Direction, text_annotations::TextAnnotations,
3131 unicode::segmentation::UnicodeSegmentation, Position, Syntax,
3232};
3333use helix_view::{
@@ -690,20 +690,20 @@ impl<T: Item + 'static> Picker<T> {
690690 }
691691 };
692692
693− // 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)
699− })
700− .unwrap_or(0);
701−
702− let offset = ViewPosition {
703− anchor: doc.text().line_to_char(first_line),
704− horizontal_offset: 0,
705− vertical_offset: 0,
706− };
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),
700+ // align to middle
701+ -(inner.height as isize / 2),
702+ 0,
703+ &text_fmt,
704+ &annotations,
705+ );
706+ }
707707
708708 let mut highlights = EditorView::doc_syntax_highlights(
709709 doc,