Skip to content

Commit

Permalink
fix crash in picker preview for invalid ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalkuthe authored and archseer committed Sep 14, 2023
1 parent e41bee6 commit e9d0bd7
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions helix-term/src/ui/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>",
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e9d0bd7

Please sign in to comment.