feat: complete files plainly if tab query begins with quotes (workaround #183)

lua-history
TorchedSammy 2022-07-09 10:45:11 -04:00
parent 587d08773f
commit d27ce26be0
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
1 changed files with 32 additions and 2 deletions

View File

@ -11,8 +11,34 @@ import (
rt "github.com/arnodel/golua/runtime" rt "github.com/arnodel/golua/runtime"
) )
func splitQuote(str string) []string {
split := []string{}
sb := &strings.Builder{}
quoted := false
for _, r := range str {
if r == '"' {
quoted = !quoted
sb.WriteRune(r)
} else if !quoted && r == ' ' {
split = append(split, sb.String())
sb.Reset()
} else {
sb.WriteRune(r)
}
}
if sb.Len() > 0 {
split = append(split, sb.String())
}
return split
}
func fileComplete(query, ctx string, fields []string) ([]string, string) { func fileComplete(query, ctx string, fields []string) ([]string, string) {
return matchPath(query) q := splitQuote(ctx)
return matchPath(q[len(q) - 1])
} }
func binaryComplete(query, ctx string, fields []string) ([]string, string) { func binaryComplete(query, ctx string, fields []string) ([]string, string) {
@ -68,6 +94,8 @@ func binaryComplete(query, ctx string, fields []string) ([]string, string) {
} }
func matchPath(query string) ([]string, string) { func matchPath(query string) ([]string, string) {
oldQuery := query
query = strings.TrimPrefix(query, "\"")
var entries []string var entries []string
var baseName string var baseName string
@ -87,7 +115,9 @@ func matchPath(query string) ([]string, string) {
if file.IsDir() { if file.IsDir() {
entry = entry + string(os.PathSeparator) entry = entry + string(os.PathSeparator)
} }
if !strings.HasPrefix(oldQuery, "\"") {
entry = escapeFilename(entry) entry = escapeFilename(entry)
}
entries = append(entries, entry) entries = append(entries, entry)
} }
} }