diff options
author | Kalyan Sriram <kalyan@coderkalyan.com> | 2021-12-15 02:30:00 +0000 |
---|---|---|
committer | delthas <delthas@dille.cc> | 2022-02-10 12:21:19 +0100 |
commit | 7b559b37b187cb8348fac4c7259ec76a848204f2 (patch) | |
tree | 07487bb35954c9eb789db636f0d2a6ff19533d56 /completions.go | |
parent | ui: buffers: sort buffer list (diff) |
ui: add commands completion
Diffstat (limited to 'completions.go')
-rw-r--r-- | completions.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/completions.go b/completions.go index 3e4a516..4c8ff28 100644 --- a/completions.go +++ b/completions.go @@ -99,6 +99,36 @@ func (app *App) completionsMsg(cs []ui.Completion, cursorIdx int, text []rune) [ return cs } +func (app *App) completionsCommands(cs []ui.Completion, cursorIdx int, text []rune) []ui.Completion { + if !hasPrefix(text, []rune("/")) { + return cs + } + for i := 0; i < cursorIdx; i++ { + if text[i] == ' ' { + return cs + } + } + if cursorIdx < len(text) && text[cursorIdx] != ' ' { + return cs + } + + uText := strings.ToUpper(string(text[1:cursorIdx])) + for name, _ := range commands { + if strings.HasPrefix(name, uText) { + c := make([]rune, len(text)+len(name)-len(uText)) + copy(c[:1], []rune("/")) + copy(c[1:], []rune(strings.ToLower(name))) + copy(c[1+len(name):], text[cursorIdx:]) + + cs = append(cs, ui.Completion{ + Text: c, + CursorIdx: 1 + len(name), + }) + } + } + return cs +} + func hasPrefix(s, prefix []rune) bool { return len(prefix) <= len(s) && equal(prefix, s[:len(prefix)]) } |