From 89aef8ba76a1d360ccb04d5b5a493f80eafa3ef0 Mon Sep 17 00:00:00 2001 From: rabite Date: Sun, 26 Jan 2020 15:40:13 +0100 Subject: fix crash when completing --- src/minibuffer.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/minibuffer.rs b/src/minibuffer.rs index d2d4f56..d6d4e47 100644 --- a/src/minibuffer.rs +++ b/src/minibuffer.rs @@ -244,7 +244,7 @@ impl MiniBuffer { let last_len = last_comp.len(); self.input = self.input.trim_end_matches(last_comp).to_string(); - self.position -= last_len; + self.position = self.position.saturating_sub(last_len); let next_comp = self.completions.pop()?; let next_comp = next_comp.to_string_lossy(); @@ -366,7 +366,7 @@ pub fn find_bins(comp_name: &str) -> HResult> { let name = file.file_name(); // If length is different that means the file starts with comp_name - if &name.trim_start(&name).len() != &comp_name.len() { + if &name.trim_start(comp_name).len() != &name.len() { Ok(name) } else { Err(HError::NoCompletionsError) @@ -375,9 +375,10 @@ pub fn find_bins(comp_name: &str) -> HResult> { }) }) }).flatten() - .flatten() - .filter_map(|s| s.ok()) - .collect::>(); + .flatten() + .filter(|s| s.is_ok()) + .map(|s| s.unwrap()) + .collect::>(); if completions.is_empty() { return Err(HError::NoCompletionsError); } -- cgit v1.2.3