@@ -710,18 +710,30 @@ impl<T: Item + 'static> Picker<T> {
712 let mut offset = ViewPosition::default();
712 let mut offset = ViewPosition::default();
713− if let Some(range) = range {
713+ if let Some((start_line, end_line)) = range {
714+ let height = end_line - start_line;
715+ let text = doc.text().slice(..);
716+ let start = text.line_to_char(start_line);
717+ let middle = text.line_to_char(start_line + height / 2);
718+ if height < inner.height as usize {
714− let text_fmt = doc.text_format(inner.width, None);
719+ let text_fmt = doc.text_format(inner.width, None);
715− let annotations = TextAnnotations::default();
720+ let annotations = TextAnnotations::default();
716− (offset.anchor, offset.vertical_offset) = char_idx_at_visual_offset(
721+ (offset.anchor, offset.vertical_offset) = char_idx_at_visual_offset(
717− doc.text().slice(..),
722+ text,
718− doc.text().line_to_char(range.0),
723+ middle,
719− // align to middle
724+ // align to middle
720− -(inner.height as isize / 2),
725+ -(inner.height as isize / 2),
722− &text_fmt,
727+ &text_fmt,
723− &annotations,
728+ &annotations,
730+ if start < offset.anchor {
731+ offset.anchor = start;
732+ offset.vertical_offset = 0;
735+ offset.anchor = start;
727 let mut highlights = EditorView::doc_syntax_highlights(
739 let mut highlights = EditorView::doc_syntax_highlights(