diff --git a/kitty_tests/completion.py b/kitty_tests/completion.py index 271bddd5e..616683104 100644 --- a/kitty_tests/completion.py +++ b/kitty_tests/completion.py @@ -121,6 +121,9 @@ def completion(self: TestCompletion, tdir: str): add('kitty -1 ', does_not_have_words('@ls', '@')) add('kitty --directory ', all_words('bin/', 'sub/')) add('kitty -1d ', all_words('bin/', 'sub/')) + add('kitty -1d', all_words('-1d')) + add('kitty --directory=', all_words('--directory=bin/', '--directory=sub/')) + add('kitty --start-as=m', all_words('--start-as=minimized', '--start-as=maximized')) for cmd, tests, result in zip(all_cmds, all_tests, run_tool()): self.current_cmd = cmd diff --git a/tools/completion/parse-args.go b/tools/completion/parse-args.go index eb11d7b4b..bf6977b25 100644 --- a/tools/completion/parse-args.go +++ b/tools/completion/parse-args.go @@ -91,8 +91,8 @@ func complete_word(word string, completions *Completions, only_args_allowed bool option := cmd.find_option(word[:idx]) if option != nil { if option.Completion_for_arg != nil { - completions.WordPrefix = word[:idx+1] option.Completion_for_arg(completions, word[idx+1:], arg_num) + completions.add_prefix_to_all_matches(word[:idx+1]) } } } else { diff --git a/tools/completion/types.go b/tools/completion/types.go index ff305f17e..8aca3807c 100644 --- a/tools/completion/types.go +++ b/tools/completion/types.go @@ -14,7 +14,6 @@ type MatchGroup struct { NoTrailingSpace bool `json:"no_trailing_space,omitempty"` IsFiles bool `json:"is_files,omitempty"` Matches []*Match `json:"matches,omitempty"` - WordPrefix string `json:"word_prefix,omitempty"` } func (self *MatchGroup) add_match(word string, description ...string) *Match { @@ -24,14 +23,21 @@ func (self *MatchGroup) add_match(word string, description ...string) *Match { } type Completions struct { - Groups []*MatchGroup `json:"groups,omitempty"` - WordPrefix string `json:"word_prefix,omitempty"` + Groups []*MatchGroup `json:"groups,omitempty"` current_cmd *Command all_words []string // all words passed to parse_args() current_word_idx int // index of current word in all_words } +func (self *Completions) add_prefix_to_all_matches(prefix string) { + for _, mg := range self.Groups { + for _, m := range mg.Matches { + m.Word = prefix + m.Word + } + } +} + func (self *Completions) add_match_group(title string) *MatchGroup { for _, q := range self.Groups { if q.Title == title {