Add autocomplete

This commit is contained in:
Zachary Yedidia
2019-06-16 15:56:39 -04:00
parent a5cf06026a
commit 8d85cae4c0
6 changed files with 156 additions and 8 deletions

View File

@@ -560,10 +560,22 @@ func (h *BufPane) OutdentSelection() bool {
// InsertTab inserts a tab or spaces
func (h *BufPane) InsertTab() bool {
indent := h.Buf.IndentString(util.IntOpt(h.Buf.Settings["tabsize"]))
tabBytes := len(indent)
bytesUntilIndent := tabBytes - (h.Cursor.GetVisualX() % tabBytes)
h.Buf.Insert(h.Cursor.Loc, indent[:bytesUntilIndent])
b := h.Buf
if b.HasSuggestions {
b.CycleAutocomplete(true)
return true
}
l := b.LineBytes(h.Cursor.Y)
l = util.SliceStart(l, h.Cursor.X)
hasComplete := b.Autocomplete(buffer.BufferComplete)
if !hasComplete {
indent := b.IndentString(util.IntOpt(b.Settings["tabsize"]))
tabBytes := len(indent)
bytesUntilIndent := tabBytes - (h.Cursor.GetVisualX() % tabBytes)
b.Insert(h.Cursor.Loc, indent[:bytesUntilIndent])
return true
}
return true
}

View File

@@ -227,6 +227,9 @@ func (h *BufPane) HandleEvent(event tcell.Event) {
func (h *BufPane) DoKeyEvent(e Event) bool {
if action, ok := BufKeyBindings[e]; ok {
estr := BufKeyStrings[e]
if estr != "InsertTab" {
h.Buf.HasSuggestions = false
}
for _, s := range MultiActions {
if s == estr {
cursors := h.Buf.GetCursors()

View File

@@ -157,12 +157,17 @@ var InfoOverrides = map[string]InfoKeyAction{
"QuitAll": (*InfoPane).QuitAll,
}
// CursorUp cycles history up
func (h *InfoPane) CursorUp() {
h.UpHistory(h.History[h.PromptType])
}
// CursorDown cycles history down
func (h *InfoPane) CursorDown() {
h.DownHistory(h.History[h.PromptType])
}
// InsertTab begins autocompletion
func (h *InfoPane) InsertTab() {
b := h.Buf
if b.HasSuggestions {
@@ -187,22 +192,32 @@ func (h *InfoPane) InsertTab() {
}
}
}
// 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 {
h.DonePrompt(false)
}
}
// Quit cancels the prompt
func (h *InfoPane) Quit() {
h.DonePrompt(true)
}
// QuitAll cancels the prompt
func (h *InfoPane) QuitAll() {
h.DonePrompt(true)
}
// Escape cancels the prompt
func (h *InfoPane) Escape() {
h.DonePrompt(true)
}