diff options
author | Hubert Hirtz <hubert@hirtz.pm> | 2021-03-04 17:59:35 +0100 |
---|---|---|
committer | Hubert Hirtz <hubert@hirtz.pm> | 2021-03-04 17:59:35 +0100 |
commit | 2cb8cf55ea1edb7be6142ae4e9b2a514a2e3173d (patch) | |
tree | 1a0854b442651f333a113f859c071a6ff52f6f6b /ui/editor.go | |
parent | Do not use dim styles on the buffer list (diff) |
Support cycling backward in auto-completions
Diffstat (limited to 'ui/editor.go')
-rw-r--r-- | ui/editor.go | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/ui/editor.go b/ui/editor.go index 16e9532..66774e0 100644 --- a/ui/editor.go +++ b/ui/editor.go @@ -212,23 +212,21 @@ func (e *Editor) Down() { e.End() } -func (e *Editor) AutoComplete() (ok bool) { +func (e *Editor) AutoComplete(offset int) (ok bool) { if e.autoCache == nil { e.autoCache = e.autoComplete(e.cursorIdx, e.text[e.lineIdx]) - if e.autoCache == nil { - return false - } if len(e.autoCache) == 0 { e.autoCache = nil return false } e.autoCacheIdx = 0 + } else { + e.autoCacheIdx = (e.autoCacheIdx + len(e.autoCache) + offset) % len(e.autoCache) } e.text[e.lineIdx] = e.autoCache[e.autoCacheIdx].Text e.cursorIdx = e.autoCache[e.autoCacheIdx].CursorIdx e.computeTextWidth() - e.autoCacheIdx = (e.autoCacheIdx + 1) % len(e.autoCache) if len(e.textWidth) <= e.offsetIdx { e.offsetIdx = 0 } |