diff options
author | Jesse Luehrs | 2023-08-08 01:06:51 +0000 |
---|---|---|
committer | GitHub | 2023-08-08 01:06:51 +0000 |
commit | a7a145ad3d78dc0b9f7c2ea289e07d60d9b51d30 (patch) | |
tree | a7db6c869094818da0feb4afdac34798b40ec452 /helix-term/src/ui | |
parent | c7e9e94f007e04836d134cd3e53f71c38b7ba1ec (diff) |
Center the picker preview selection using visual lines (#7837)
this way the preview always shows the selection even if lines were
wrapped
Diffstat (limited to 'helix-term/src/ui')
-rw-r--r-- | helix-term/src/ui/picker.rs | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index f80bc512..5ee4c407 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -27,7 +27,7 @@ use std::{collections::HashMap, io::Read, path::PathBuf}; use crate::ui::{Prompt, PromptEvent}; use helix_core::{ - movement::Direction, text_annotations::TextAnnotations, + char_idx_at_visual_offset, movement::Direction, text_annotations::TextAnnotations, unicode::segmentation::UnicodeSegmentation, Position, Syntax, }; use helix_view::{ @@ -690,20 +690,20 @@ impl<T: Item + 'static> Picker<T> { } }; - // align to middle - let first_line = range - .map(|(start, end)| { - let height = end.saturating_sub(start) + 1; - let middle = start + (height.saturating_sub(1) / 2); - middle.saturating_sub(inner.height as usize / 2).min(start) - }) - .unwrap_or(0); - - let offset = ViewPosition { - anchor: doc.text().line_to_char(first_line), - horizontal_offset: 0, - vertical_offset: 0, - }; + let mut offset = ViewPosition::default(); + if let Some(range) = range { + let text_fmt = doc.text_format(inner.width, None); + let annotations = TextAnnotations::default(); + (offset.anchor, offset.vertical_offset) = char_idx_at_visual_offset( + doc.text().slice(..), + doc.text().line_to_char(range.0), + // align to middle + -(inner.height as isize / 2), + 0, + &text_fmt, + &annotations, + ); + } let mut highlights = EditorView::doc_syntax_highlights( doc, |