|
|
@ -26,7 +26,7 @@ use helix_view::{
|
|
|
|
pub const MIN_SCREEN_WIDTH_FOR_PREVIEW: u16 = 80;
|
|
|
|
pub const MIN_SCREEN_WIDTH_FOR_PREVIEW: u16 = 80;
|
|
|
|
|
|
|
|
|
|
|
|
/// File path and line number (used to align and highlight a line)
|
|
|
|
/// File path and line number (used to align and highlight a line)
|
|
|
|
type FileLocation = (PathBuf, Option<usize>);
|
|
|
|
type FileLocation = (PathBuf, Option<(usize, usize)>);
|
|
|
|
|
|
|
|
|
|
|
|
pub struct FilePicker<T> {
|
|
|
|
pub struct FilePicker<T> {
|
|
|
|
picker: Picker<T>,
|
|
|
|
picker: Picker<T>,
|
|
|
@ -113,14 +113,17 @@ impl<T: 'static> Component for FilePicker<T> {
|
|
|
|
|
|
|
|
|
|
|
|
block.render(preview_area, surface);
|
|
|
|
block.render(preview_area, surface);
|
|
|
|
|
|
|
|
|
|
|
|
if let Some((doc, line)) = self.current_file(cx.editor).and_then(|(path, line)| {
|
|
|
|
if let Some((doc, line)) = self.current_file(cx.editor).and_then(|(path, range)| {
|
|
|
|
cx.editor
|
|
|
|
cx.editor
|
|
|
|
.document_by_path(&path)
|
|
|
|
.document_by_path(&path)
|
|
|
|
.or_else(|| self.preview_cache.get(&path))
|
|
|
|
.or_else(|| self.preview_cache.get(&path))
|
|
|
|
.zip(Some(line))
|
|
|
|
.zip(Some(range))
|
|
|
|
}) {
|
|
|
|
}) {
|
|
|
|
// align to middle
|
|
|
|
// align to middle
|
|
|
|
let first_line = line.unwrap_or(0).saturating_sub(inner.height as usize / 2);
|
|
|
|
let first_line = line
|
|
|
|
|
|
|
|
.map(|(start, _)| start)
|
|
|
|
|
|
|
|
.unwrap_or(0)
|
|
|
|
|
|
|
|
.saturating_sub(inner.height as usize / 2);
|
|
|
|
let offset = Position::new(first_line, 0);
|
|
|
|
let offset = Position::new(first_line, 0);
|
|
|
|
|
|
|
|
|
|
|
|
let highlights = EditorView::doc_syntax_highlights(
|
|
|
|
let highlights = EditorView::doc_syntax_highlights(
|
|
|
@ -140,12 +143,18 @@ impl<T: 'static> Component for FilePicker<T> {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// highlight the line
|
|
|
|
// highlight the line
|
|
|
|
if let Some(line) = line {
|
|
|
|
if let Some((start, end)) = line {
|
|
|
|
for x in inner.left()..inner.right() {
|
|
|
|
let offset = start.saturating_sub(first_line) as u16;
|
|
|
|
surface
|
|
|
|
surface.set_style(
|
|
|
|
.get_mut(x, inner.y + line.saturating_sub(first_line) as u16)
|
|
|
|
Rect::new(
|
|
|
|
.set_style(cx.editor.theme.get("ui.selection"));
|
|
|
|
inner.x,
|
|
|
|
}
|
|
|
|
inner.y + offset,
|
|
|
|
|
|
|
|
inner.width,
|
|
|
|
|
|
|
|
(end.saturating_sub(start) as u16 + 1)
|
|
|
|
|
|
|
|
.min(inner.height.saturating_sub(offset)),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
cx.editor.theme.get("ui.selection"),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|