commit 2cb8cf5
Hubert Hirtz
·
2021-03-04 16:59:35 +0000 UTC
parent a9d5336
Support cycling backward in auto-completions
3 files changed,
+11,
-8
M
app.go
+6,
-1
1@@ -444,7 +444,12 @@ func (app *App) handleKeyEvent(ev *tcell.EventKey) {
2 app.updatePrompt()
3 }
4 case tcell.KeyTab:
5- ok := app.win.InputAutoComplete()
6+ ok := app.win.InputAutoComplete(1)
7+ if ok {
8+ app.typing()
9+ }
10+ case tcell.KeyBacktab:
11+ ok := app.win.InputAutoComplete(-1)
12 if ok {
13 app.typing()
14 }
+3,
-5
1@@ -212,23 +212,21 @@ func (e *Editor) Down() {
2 e.End()
3 }
4
5-func (e *Editor) AutoComplete() (ok bool) {
6+func (e *Editor) AutoComplete(offset int) (ok bool) {
7 if e.autoCache == nil {
8 e.autoCache = e.autoComplete(e.cursorIdx, e.text[e.lineIdx])
9- if e.autoCache == nil {
10- return false
11- }
12 if len(e.autoCache) == 0 {
13 e.autoCache = nil
14 return false
15 }
16 e.autoCacheIdx = 0
17+ } else {
18+ e.autoCacheIdx = (e.autoCacheIdx + len(e.autoCache) + offset) % len(e.autoCache)
19 }
20
21 e.text[e.lineIdx] = e.autoCache[e.autoCacheIdx].Text
22 e.cursorIdx = e.autoCache[e.autoCacheIdx].CursorIdx
23 e.computeTextWidth()
24- e.autoCacheIdx = (e.autoCacheIdx + 1) % len(e.autoCache)
25 if len(e.textWidth) <= e.offsetIdx {
26 e.offsetIdx = 0
27 }
M
ui/ui.go
+2,
-2
1@@ -192,8 +192,8 @@ func (ui *UI) InputDelete() (ok bool) {
2 return ui.e.RemRuneForward()
3 }
4
5-func (ui *UI) InputAutoComplete() (ok bool) {
6- return ui.e.AutoComplete()
7+func (ui *UI) InputAutoComplete(offset int) (ok bool) {
8+ return ui.e.AutoComplete(offset)
9 }
10
11 func (ui *UI) InputEnter() (content string) {