mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-17 22:37:10 +09:00
Fix undo autocomplete
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user