From f5c6829670299307086b60d214978729a3ab4322 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 19 Oct 2024 17:16:21 +0200 Subject: [PATCH] Fix pager being blank when token prefix contains newline Given $ echo {\ C where C is the cursor. Completions have prefix "{\\\n". Since \n has a wcwidth of -1, this line always fails let prefix_len = usize::try_from(fish_wcswidth(&self.prefix)); This triggers uncovers a regression in 43e2d7b48 (Port pager.cpp, 2023-12-02), where we end up computing comp_width=0 for all completions. Fix this. Test in the next commit. The C++ version added the prefix width only if the completion had a valid width. That seems wrong, let's do it always (if the prefix width is valid). --- src/pager.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/pager.rs b/src/pager.rs index 176e81cf6..1ef287ece 100644 --- a/src/pager.rs +++ b/src/pager.rs @@ -356,10 +356,8 @@ impl Pager { // fish_wcswidth() can return -1 if it can't calculate the width. So be cautious. let comp_width = fish_wcswidth(comp_string); - if let (Ok(prefix_len), Ok(comp_width)) = (prefix_len, usize::try_from(comp_width)) - { - comp.comp_width += prefix_len + comp_width; - } + comp.comp_width += prefix_len.unwrap_or_default(); + comp.comp_width += usize::try_from(comp_width).unwrap_or_default(); } // fish_wcswidth() can return -1 if it can't calculate the width. So be cautious.