@@ -26,7 +26,7 @@ use helix_view::{
2626pub const MIN_SCREEN_WIDTH_FOR_PREVIEW: u16 = 80;
2727
2828/// File path and line number (used to align and highlight a line)
29−type FileLocation = (PathBuf, Option<usize>);
29+type FileLocation = (PathBuf, Option<(usize, usize)>);
3030
3131pub struct FilePicker<T> {
3232 picker: Picker<T>,
@@ -113,14 +113,17 @@ impl<T: 'static> Component for FilePicker<T> {
113113
114114 block.render(preview_area, surface);
115115
116− if let Some((doc, line)) = self.current_file(cx.editor).and_then(|(path, line)| {
116+ if let Some((doc, line)) = self.current_file(cx.editor).and_then(|(path, range)| {
117117 cx.editor
118118 .document_by_path(&path)
119119 .or_else(|| self.preview_cache.get(&path))
120− .zip(Some(line))
120+ .zip(Some(range))
121121 }) {
122122 // align to middle
123− let first_line = line.unwrap_or(0).saturating_sub(inner.height as usize / 2);
123+ let first_line = line
124+ .map(|(start, _)| start)
125+ .unwrap_or(0)
126+ .saturating_sub(inner.height as usize / 2);
124127 let offset = Position::new(first_line, 0);
125128
126129 let highlights = EditorView::doc_syntax_highlights(
@@ -140,12 +143,18 @@ impl<T: 'static> Component for FilePicker<T> {
140143 );
141144
142145 // highlight the line
143− if let Some(line) = line {
144− for x in inner.left()..inner.right() {
145− surface
146− .get_mut(x, inner.y + line.saturating_sub(first_line) as u16)
147− .set_style(cx.editor.theme.get("ui.selection"));
148− }
146+ if let Some((start, end)) = line {
147+ let offset = start.saturating_sub(first_line) as u16;
148+ surface.set_style(
149+ Rect::new(
150+ inner.x,
151+ inner.y + offset,
152+ inner.width,
153+ (end.saturating_sub(start) as u16 + 1)
154+ .min(inner.height.saturating_sub(offset)),
155+ ),
156+ cx.editor.theme.get("ui.selection"),
157+ );
149158 }
150159 }
151160 }