aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorPascal Kuthe2023-09-12 19:11:07 +0000
committerBlaž Hrastnik2023-09-14 02:00:28 +0000
commite9d0bd7aefda6962b56245eb7d0f56b5d2fa4859 (patch)
tree4448e5ffb9643c82483960d1b1f4382bb6f0a458 /helix-term
parente41bee6ac63095a3cd74c3efba0a417d8834f0b8 (diff)
fix crash in picker preview for invalid ranges
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/ui/picker.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs
index 94a69b0d..7e745f72 100644
--- a/helix-term/src/ui/picker.rs
+++ b/helix-term/src/ui/picker.rs
@@ -112,9 +112,9 @@ impl Preview<'_, '_> {
/// Alternate text to show for the preview.
fn placeholder(&self) -> &str {
match *self {
- Self::EditorDocument(_) => "<File preview>",
+ Self::EditorDocument(_) => "<Invalid file location>",
Self::Cached(preview) => match preview {
- CachedPreview::Document(_) => "<File preview>",
+ CachedPreview::Document(_) => "<Invalid file location>",
CachedPreview::Binary => "<Binary file>",
CachedPreview::LargeFile => "<File too large to preview>",
CachedPreview::NotFound => "<File not found>",
@@ -693,8 +693,14 @@ impl<T: Item + 'static> Picker<T> {
if let Some((path, range)) = self.current_file(cx.editor) {
let preview = self.get_preview(path, cx.editor);
let doc = match preview.document() {
- Some(doc) => doc,
- None => {
+ Some(doc)
+ if range.map_or(true, |(start, end)| {
+ start <= end && end <= doc.text().len_lines()
+ }) =>
+ {
+ doc
+ }
+ _ => {
let alt_text = preview.placeholder();
let x = inner.x + inner.width.saturating_sub(alt_text.len() as u16) / 2;
let y = inner.y + inner.height / 2;