Skip to content

Commit e9d0bd7

Browse files
pascalkuthearchseer
authored andcommitted
fix crash in picker preview for invalid ranges
1 parent e41bee6 commit e9d0bd7

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

helix-term/src/ui/picker.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ impl Preview<'_, '_> {
112112
/// Alternate text to show for the preview.
113113
fn placeholder(&self) -> &str {
114114
match *self {
115-
Self::EditorDocument(_) => "<File preview>",
115+
Self::EditorDocument(_) => "<Invalid file location>",
116116
Self::Cached(preview) => match preview {
117-
CachedPreview::Document(_) => "<File preview>",
117+
CachedPreview::Document(_) => "<Invalid file location>",
118118
CachedPreview::Binary => "<Binary file>",
119119
CachedPreview::LargeFile => "<File too large to preview>",
120120
CachedPreview::NotFound => "<File not found>",
@@ -693,8 +693,14 @@ impl<T: Item + 'static> Picker<T> {
693693
if let Some((path, range)) = self.current_file(cx.editor) {
694694
let preview = self.get_preview(path, cx.editor);
695695
let doc = match preview.document() {
696-
Some(doc) => doc,
697-
None => {
696+
Some(doc)
697+
if range.map_or(true, |(start, end)| {
698+
start <= end && end <= doc.text().len_lines()
699+
}) =>
700+
{
701+
doc
702+
}
703+
_ => {
698704
let alt_text = preview.placeholder();
699705
let x = inner.x + inner.width.saturating_sub(alt_text.len() as u16) / 2;
700706
let y = inner.y + inner.height / 2;

0 commit comments

Comments
 (0)