Fix undo autocomplete

This commit is contained in:
Zachary Yedidia
2020-08-16 01:03:41 -04:00
parent 724cedd37b
commit 98b3ed0eec
4 changed files with 17 additions and 2 deletions

View File

@@ -682,7 +682,10 @@ func (h *BufPane) Autocomplete() bool {
// don't autocomplete if cursor is on alpha numeric character (middle of a word)
return false
}
return b.Autocomplete(buffer.LSPComplete)
if !b.Autocomplete(buffer.LSPComplete) {
return b.Autocomplete(buffer.BufferComplete)
}
return true
}
// CycleAutocompleteBack cycles back in the autocomplete suggestion list

View File

@@ -60,7 +60,12 @@ func (b *Buffer) CycleAutocomplete(forward bool) {
if prevCompletion != -1 {
prev := b.Completions[prevCompletion]
for i := 0; i < len(prev.Edits); i++ {
b.UndoOneEvent()
if len(prev.Edits[i].Text) != 0 {
b.UndoOneEvent()
}
if !prev.Edits[i].Start.Equal(prev.Edits[i].End) {
b.UndoOneEvent()
}
}
}

View File

@@ -2,6 +2,7 @@ package buffer
import (
"bytes"
"log"
"time"
dmp "github.com/sergi/go-diff/diffmatchpatch"
@@ -52,6 +53,7 @@ func (eh *EventHandler) DoTextEvent(t *TextEvent, useUndo bool) {
}
if len(t.Deltas) != 1 {
log.Println("Multiple deltas not supported")
return
}

View File

@@ -48,6 +48,11 @@ func (l Loc) LessEqual(b Loc) bool {
return l == b
}
// Equal returns true if two locs are equal
func (l Loc) Equal(b Loc) bool {
return l.Y == b.Y && l.X == b.X
}
// The following functions require a buffer to know where newlines are
// Diff returns the distance between two locations