feat: add case insensitive tab completion

insensitive-tab-2
TorchedSammy 2022-11-30 17:23:48 -04:00
parent 3f9b230381
commit b37715f483
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
2 changed files with 8 additions and 5 deletions

View File

@ -150,7 +150,7 @@ func matchPath(query string) ([]string, string) {
files, _ := os.ReadDir(path)
for _, file := range files {
if strings.HasPrefix(file.Name(), baseName) {
if strings.HasPrefix(strings.ToLower(file.Name()), strings.ToLower(baseName)) {
entry := file.Name()
if file.IsDir() {
entry = entry + string(os.PathSeparator)

View File

@ -74,7 +74,8 @@ func (rl *Instance) insertCandidate() {
// Ensure no indexing error happens with prefix
if len(completion) >= prefix {
rl.insert([]rune(completion[prefix:]))
rl.viDeleteByAdjust(-prefix)
rl.insert([]rune(completion))
if !cur.TrimSlash && !cur.NoSpace {
rl.insert([]rune(" "))
}
@ -86,7 +87,6 @@ func (rl *Instance) insertCandidate() {
func (rl *Instance) updateVirtualComp() {
cur := rl.getCurrentGroup()
if cur != nil {
completion := cur.getCurrentCell(rl)
prefix := len(rl.tcPrefix)
@ -99,6 +99,9 @@ func (rl *Instance) updateVirtualComp() {
rl.viUndoSkipAppend = true
rl.resetTabCompletion()
} else {
if strings.HasSuffix(string(rl.line), rl.tcPrefix) {
rl.viDeleteByAdjust(-prefix)
}
// Special case for the only special escape, which
// if not handled, will make us insert the first
@ -109,7 +112,7 @@ func (rl *Instance) updateVirtualComp() {
// Or insert it virtually.
if len(completion) >= prefix {
rl.insertCandidateVirtual([]rune(completion[prefix:]))
rl.insertCandidateVirtual([]rune(completion))
}
}
}
@ -173,7 +176,7 @@ func (rl *Instance) resetVirtualComp(drop bool) {
completion = completion + " "
}
}
rl.insertCandidateVirtual([]rune(completion[prefix:]))
rl.insertCandidateVirtual([]rune(completion))
}
// Reset virtual