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).
This commit is contained in:
Johannes Altmanninger 2024-10-19 17:16:21 +02:00
parent cd541575b4
commit f5c6829670

View File

@ -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.