Fix case-changing autosuggestions generated mid-token

This fixes a bug where a case-changing autosuggestion generated from the
middle of a token would append too much to the end of the token.

Fixes #8820
This commit is contained in:
ridiculousfish 2022-03-20 20:15:02 -07:00
parent 1763e7d3bc
commit d0d5c62ec7
3 changed files with 9 additions and 2 deletions

View file

@ -33,6 +33,7 @@ Interactive improvements
------------------------ ------------------------
- The default command-not-found handler now reports a special error if there is a non-executable file (:issue:`8804`) - The default command-not-found handler now reports a special error if there is a non-executable file (:issue:`8804`)
- ``less`` and other interactive commands would occasionally be stopped when run in a pipeline with fish functions; this has been fixed (:issue:`8699`). - ``less`` and other interactive commands would occasionally be stopped when run in a pipeline with fish functions; this has been fixed (:issue:`8699`).
- Case-changing autosuggestions generated mid-token now correctly append only the suffix, instead of duplicating the token (:issue:`8820`).
New or improved bindings New or improved bindings
^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -3327,6 +3327,13 @@ static void test_complete() {
completions.front().completion, completions.front().flags, cmdline, &where, false); completions.front().completion, completions.front().flags, cmdline, &where, false);
do_test(newcmdline == L"touch test/complete_test/bracket\\[abc\\] "); do_test(newcmdline == L"touch test/complete_test/bracket\\[abc\\] ");
// #8820
size_t cursor_pos = 11;
newcmdline =
completion_apply_to_command_line(L"Debug/", COMPLETE_REPLACES_TOKEN | COMPLETE_NO_SPACE,
L"mv debug debug", &cursor_pos, true);
do_test(newcmdline == L"mv debug Debug/");
#ifndef __CYGWIN__ // Square brackets are not legal path characters on WIN32/CYGWIN #ifndef __CYGWIN__ // Square brackets are not legal path characters on WIN32/CYGWIN
cmdline = LR"(touch test/complete_test/gnarlybracket\\[)"; cmdline = LR"(touch test/complete_test/gnarlybracket\\[)";
completions = do_complete(cmdline, {}); completions = do_complete(cmdline, {});

View file

@ -1615,8 +1615,7 @@ wcstring completion_apply_to_command_line(const wcstring &val, complete_flags_t
const wchar_t *begin, *end; const wchar_t *begin, *end;
const wchar_t *buff = command_line.c_str(); const wchar_t *buff = command_line.c_str();
parse_util_token_extent(buff, cursor_pos, &begin, nullptr, nullptr, nullptr); parse_util_token_extent(buff, cursor_pos, &begin, &end, nullptr, nullptr);
end = buff + cursor_pos;
wcstring sb(buff, begin - buff); wcstring sb(buff, begin - buff);