Fix a few completion bugs and add a few small features (#934)
* Fix some multibyte character completion bugs
- matchLongest now operates on runes instead of bytes so we don't
complete part of a multibyte character.
- Fix some places that mixed string and rune slice indices.
* Fix wrong menu completion for subdirectories
When selecting a menu completion for a file in a subdirectory, the
entire filename would be appended to the command line, even if you had
already typed part of it.
* Escape file completions in menu completion
* Minor refactors and typo fixes
* Fix cmd-menu-complete-back bug
The first use of cmd-menu-complete-back after opening the completion
menu was incorrectly selecting the before-last completion instead of the
last completion.
* Allow completing broken symlinks
Also skip files with stat errors instead of returning.
* Add command to accept current menu selection
This is useful when completing filenames. For example
cmap <c-y> :cmd-menu-accept; cmd-menu-complete
can be used to accept the selected directory completion, then complete
files in the directory.
* Complete command names for map and cmap
This commit is contained in:
1 parent
5ba70d0f61
commit
cb7aa13218
8 files changed
+137
-100
No files matched your search
@@ -1265,13 +1265,14 @@ func listMatchesMenu(ui *ui, matches []string) error {
|
||||
|
||||
// Handle menu tab match only if wanted
|
||||
if ui.menuSelected == i {
|
||||
comp := []rune(escape(target))
|
||||
toks := tokenize(string(ui.cmdAccLeft))
|
||||
last := toks[len(toks)-1]
|
||||
_, last := filepath.Split(toks[len(toks)-1])
|
||||
|
||||
if strings.Contains(target, last) {
|
||||
ui.cmdAccLeft = append(ui.cmdAccLeft[:len(ui.cmdAccLeft)-len(last)], []rune(target)...)
|
||||
if last == "" {
|
||||
ui.cmdAccLeft = append(ui.cmdAccLeft, comp...)
|
||||
} else {
|
||||
ui.cmdAccLeft = append(ui.cmdAccLeft, []rune(target)...)
|
||||
ui.cmdAccLeft = append(ui.cmdAccLeft[:len(ui.cmdAccLeft)-len([]rune(last))], comp...)
|
||||
}
|
||||
|
||||
target = fmt.Sprintf("\033[7m%s\033[0m%*s", target, wcol-len(target), "")
|
||||
|
||||
Reference in new issue
Block a user