autocomplete: Escape spaces and quotes in filename completions - #4224
autocomplete: Escape spaces and quotes in filename completions#4224anandghegde wants to merge 1 commit into
Conversation
Commands and the save-as prompt split their input with shellquote, so a completed name like "my folder/" was split into two arguments and the following completion started from "folder/". Escape spaces and quotes in the inserted completion and treat such escapes as part of the argument when completing. Fixes micro-editor#3970 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MA8JGs7pCoXFL2W6jEJ8sD
Andriamanitra
left a comment
There was a problem hiding this comment.
Making this specific to FileComplete doesn't make sense to me. All other commands can also accept arguments with backslash escaped spaces. Is there a reason to introduce a new function getFileArg instead of simply fixing GetArg?
To answer my own question: The same Footnotes
|
|
Right, that was the reason. Also, making
Filenames are the only case where the bug shows up, so I kept the fix in |
Fixes #3970
Filename completion puts names with spaces into the prompt as-is, but
open,tab,vsplit,cd,saveand the save-as prompt all split their input with shellquote. SoCtrl-o→my→Tabgivesopen my folder/, and pressing Enter opens an empty buffer namedmy. Completing further inside that folder also fails, becauseGetArgtreatsfolder/...as a new argument.This change:
FileCompleteinserts (the suggestion list still shows plain names)FileCompletetreat those backslash escapes as part of the current argument and strip them before looking up the directory, so completion keeps working insidemy\ folder/Only a backslash in front of one of those characters counts as an escape, so other backslashes, like Windows path separators, are handled the same as before.
GetArgand the other completers are unchanged.Before (master), with a
my folder/it's a file.txtfile:After:
Testing:
TestFileCompleteEscapesSpecialCharsininternal/buffer/autocomplete_test.go. It fails on master and passes with the fix.make test(go test ./internal/... ./cmd/... plus the gofmt check) passes on macOS with Go 1.27.Note: #4178 (Windows path separators) also edits the start of
FileCompleteand addsautocomplete_test.go. The two changes are separate, but whichever merges second will need a small rebase. I'm happy to do that.I used Claude Code to write this change. I reviewed and tested it myself.
🤖 Generated with Claude Code
https://claude.ai/code/session_01MA8JGs7pCoXFL2W6jEJ8sD