Fix tab completion for commands like: ``` cd "[2025] Tax Documents" ``` while still allowing tab completion for commands like: ``` copy file1+file2 file3 ``` to work.
Without this change, tab completion for cd "[2025] Tax Documents" yields cd "[2025][2025] Tax Documents". Completed text is inserted into the incorrect location due to the closing ']' which was erroneously interpreted as a delimiter before this change.
From: Joe Souza jsouza@yahoo.com
--- programs/cmd/wcmdmain.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c index fbec86a481a..31fa5e795b9 100644 --- a/programs/cmd/wcmdmain.c +++ b/programs/cmd/wcmdmain.c @@ -193,12 +193,25 @@ static void find_insert_pos(const WCHAR *inputBuffer, int len, SEARCH_CONTEXT *s /* Handle paths here. Find last '\' or other delimiter. * If not found then insert pos is the same as search pos. */ - while (cc > sc->search_pos && !wcschr(INTRA_PATH_DELIMS, inputBuffer[cc])) { - cc--; - } + if (sc->user_specified_quotes) { + /* If the user specified quotes then treat the usual delimiters as literals + * and ignore them. + */ + while (cc > sc->search_pos && inputBuffer[cc] != L'\') { + cc--; + } + + if (inputBuffer[cc] == L'"' || inputBuffer[cc] == L'\') { + cc++; + } + } else { + while (cc > sc->search_pos && !wcschr(INTRA_PATH_DELIMS, inputBuffer[cc])) { + cc--; + }
- if (inputBuffer[cc] == L'"' || wcschr(INTRA_PATH_DELIMS, inputBuffer[cc])) { - cc++; + if (inputBuffer[cc] == L'"' || wcschr(INTRA_PATH_DELIMS, inputBuffer[cc])) { + cc++; + } }
sc->insert_pos = cc;