Center the picker preview selection using visual lines (#7837)

this way the preview always shows the selection even if lines were
wrapped
pull/7494/merge
Jesse Luehrs 11 months ago committed by GitHub
parent c7e9e94f00
commit a7a145ad3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -27,7 +27,7 @@ use std::{collections::HashMap, io::Read, path::PathBuf};
use crate::ui::{Prompt, PromptEvent}; use crate::ui::{Prompt, PromptEvent};
use helix_core::{ use helix_core::{
movement::Direction, text_annotations::TextAnnotations, char_idx_at_visual_offset, movement::Direction, text_annotations::TextAnnotations,
unicode::segmentation::UnicodeSegmentation, Position, Syntax, unicode::segmentation::UnicodeSegmentation, Position, Syntax,
}; };
use helix_view::{ use helix_view::{
@ -690,20 +690,20 @@ impl<T: Item + 'static> Picker<T> {
} }
}; };
// align to middle let mut offset = ViewPosition::default();
let first_line = range if let Some(range) = range {
.map(|(start, end)| { let text_fmt = doc.text_format(inner.width, None);
let height = end.saturating_sub(start) + 1; let annotations = TextAnnotations::default();
let middle = start + (height.saturating_sub(1) / 2); (offset.anchor, offset.vertical_offset) = char_idx_at_visual_offset(
middle.saturating_sub(inner.height as usize / 2).min(start) doc.text().slice(..),
}) doc.text().line_to_char(range.0),
.unwrap_or(0); // align to middle
-(inner.height as isize / 2),
let offset = ViewPosition { 0,
anchor: doc.text().line_to_char(first_line), &text_fmt,
horizontal_offset: 0, &annotations,
vertical_offset: 0, );
}; }
let mut highlights = EditorView::doc_syntax_highlights( let mut highlights = EditorView::doc_syntax_highlights(
doc, doc,

Loading…
Cancel
Save