From d234e9ec41b32aea28d5faa16d197bf9818a9169 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Sat, 4 Jan 2020 15:51:15 -0500 Subject: [PATCH] Add cycleautocompleteback action --- internal/action/actions.go | 16 ++++++++++++++++ internal/action/bindings.go | 2 +- internal/action/bufpane.go | 3 ++- internal/action/infopane.go | 8 -------- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/internal/action/actions.go b/internal/action/actions.go index 67e5dbd5..a85f7bbb 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -1,6 +1,7 @@ package action import ( + "log" "regexp" "runtime" "strings" @@ -611,6 +612,21 @@ func (h *BufPane) Autocomplete() bool { return b.Autocomplete(buffer.BufferComplete) } +// CycleAutocompleteBack cycles back in the autocomplete suggestion list +func (h *BufPane) CycleAutocompleteBack() bool { + if h.Cursor.HasSelection() { + return false + } + log.Println(h.Buf.HasSuggestions) + + if h.Buf.HasSuggestions { + h.Buf.CycleAutocomplete(false) + log.Println("TRUE") + return true + } + return false +} + // InsertTab inserts a tab or spaces func (h *BufPane) InsertTab() bool { b := h.Buf diff --git a/internal/action/bindings.go b/internal/action/bindings.go index 5d469c76..8984c043 100644 --- a/internal/action/bindings.go +++ b/internal/action/bindings.go @@ -422,7 +422,7 @@ func DefaultBindings() map[string]string { "Alt-CtrlH": "DeleteWordLeft", "Alt-Backspace": "DeleteWordLeft", "Tab": "Autocomplete|IndentSelection|InsertTab", - "Backtab": "OutdentSelection|OutdentLine", + "Backtab": "CycleAutocompleteBack|OutdentSelection|OutdentLine", "CtrlO": "OpenFile", "CtrlS": "Save", "CtrlF": "Find", diff --git a/internal/action/bufpane.go b/internal/action/bufpane.go index f3a734da..fdd8a5b4 100644 --- a/internal/action/bufpane.go +++ b/internal/action/bufpane.go @@ -355,7 +355,7 @@ func (h *BufPane) DoKeyEvent(e Event) bool { } func (h *BufPane) execAction(action func(*BufPane) bool, name string, cursor int) bool { - if name != "Autocomplete" { + if name != "Autocomplete" && name != "CycleAutocompleteBack" { h.Buf.HasSuggestions = false } @@ -523,6 +523,7 @@ var BufKeyActions = map[string]BufKeyAction{ "IndentSelection": (*BufPane).IndentSelection, "OutdentSelection": (*BufPane).OutdentSelection, "Autocomplete": (*BufPane).Autocomplete, + "CycleAutocompleteBack": (*BufPane).CycleAutocompleteBack, "OutdentLine": (*BufPane).OutdentLine, "Paste": (*BufPane).Paste, "PastePrimary": (*BufPane).PastePrimary, diff --git a/internal/action/infopane.go b/internal/action/infopane.go index 00dde633..acff3597 100644 --- a/internal/action/infopane.go +++ b/internal/action/infopane.go @@ -154,7 +154,6 @@ var InfoOverrides = map[string]InfoKeyAction{ "CursorDown": (*InfoPane).CursorDown, "InsertNewline": (*InfoPane).InsertNewline, "Autocomplete": (*InfoPane).Autocomplete, - "OutdentLine": (*InfoPane).CycleBack, "Escape": (*InfoPane).Escape, "Quit": (*InfoPane).Quit, "QuitAll": (*InfoPane).QuitAll, @@ -196,13 +195,6 @@ func (h *InfoPane) Autocomplete() { } } -// CycleBack cycles back in the autocomplete suggestion list -func (h *InfoPane) CycleBack() { - if h.Buf.HasSuggestions { - h.Buf.CycleAutocomplete(false) - } -} - // InsertNewline completes the prompt func (h *InfoPane) InsertNewline() { if !h.HasYN {