Auto accept completion when only a single candidate is present

This commit is contained in:
Kovid Goyal 2023-03-07 16:48:53 +05:30
parent 0e73c01093
commit ea1842407d
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -102,6 +102,7 @@ func (self *Readline) complete(forwards bool, repeat_count uint) bool {
} }
ct := c.current.current_match_text() ct := c.current.current_match_text()
if ct != "" { if ct != "" {
all_text_before_completion := self.AllText()
before := c.current.before_cursor[:c.current.results.CurrentWordIdx] + ct before := c.current.before_cursor[:c.current.results.CurrentWordIdx] + ct
after := c.current.after_cursor after := c.current.after_cursor
self.input_state.lines = utils.Splitlines(before) self.input_state.lines = utils.Splitlines(before)
@ -115,6 +116,13 @@ func (self *Readline) complete(forwards bool, repeat_count uint) bool {
self.input_state.lines[self.input_state.cursor.Y] += al[0] self.input_state.lines[self.input_state.cursor.Y] += al[0]
self.input_state.lines = append(self.input_state.lines, al[1:]...) self.input_state.lines = append(self.input_state.lines, al[1:]...)
} }
if c.current.num_of_matches == 1 && self.AllText() == all_text_before_completion {
// when there is onlya single match and it has already been inserted there is no point iterating over current completions
orig := self.last_action
self.last_action = ActionNil
self.complete(true, 1)
self.last_action = orig
}
} }
if repeat_count > 0 { if repeat_count > 0 {
self.complete(forwards, repeat_count) self.complete(forwards, repeat_count)