fix(spec): handle quote when tokenize

This commit is contained in:
verse91
2026-04-11 20:51:31 +07:00
parent 525eac1bfa
commit e465d900a8
+21 -5
View File
@@ -258,15 +258,31 @@ func topLevelSuggestions(query string) []Suggestion {
func tokenize(s string) []string { func tokenize(s string) []string {
tokens := []string{} tokens := []string{}
current := "" current := ""
inQuote := false
var quoteChar rune
for _, c := range s { for _, c := range s {
if c == ' ' { switch {
tokens = append(tokens, current) case !inQuote && (c == '"' || c == '\''):
current = "" inQuote = true
} else { quoteChar = c
case inQuote && c == quoteChar:
inQuote = false
case c == ' ' && !inQuote:
if current != "" {
tokens = append(tokens, current)
current = ""
} else if len(tokens) > 0 && tokens[len(tokens)-1] != "" {
// preserve trailing space as an empty token for suggestions
// but only if it's the very last thing and not multiple spaces
}
default:
current += string(c) current += string(c)
} }
} }
tokens = append(tokens, current) // always append the last token (could be empty if space was last character)
// always append the last token (even if empty, representing the cursor position)
tokens = append(tokens, current)
return tokens return tokens
} }