More work on readline completion

This commit is contained in:
Kovid Goyal
2022-11-12 11:27:27 +05:30
parent 4974219e0f
commit 9e2c96653f
5 changed files with 80 additions and 16 deletions

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"kitty/tools/cli"
"kitty/tools/utils"
)
var _ = fmt.Print
@@ -39,7 +40,11 @@ func (self *completion) current_match_text() string {
for _, g := range self.results.Groups {
for _, m := range g.Matches {
if i == self.current_match {
return m.Word
t := m.Word
if !g.NoTrailingSpace {
t += " "
}
return t
}
i++
}
@@ -83,6 +88,19 @@ func (self *Readline) complete(forwards bool, repeat_count uint) bool {
}
ct := c.current.current_match_text()
if ct != "" {
before := c.current.before_cursor[:c.current.results.CurrentWordIdx] + ct
after := c.current.after_cursor
self.input_state.lines = utils.Splitlines(before)
if len(self.input_state.lines) == 0 {
self.input_state.lines = []string{""}
}
self.input_state.cursor.Y = len(self.input_state.lines) - 1
self.input_state.cursor.X = len(self.input_state.lines[self.input_state.cursor.Y])
al := utils.Splitlines(after)
if len(al) > 0 {
self.input_state.lines[self.input_state.cursor.Y] += al[0]
self.input_state.lines = append(self.input_state.lines, al[1:]...)
}
}
if repeat_count > 0 {
self.complete(forwards, repeat_count)