diff --git a/cmd/micro/actions.go b/cmd/micro/actions.go index c09f2a4e..5b29e1e9 100644 --- a/cmd/micro/actions.go +++ b/cmd/micro/actions.go @@ -1916,17 +1916,15 @@ func (v *View) SkipMultiCursor(usePlugin bool) bool { func (v *View) RemoveMultiCursor(usePlugin bool) bool { end := len(v.Buf.cursors) if end > 1 { - nextOne := v.Buf.cursors[len(v.Buf.cursors)-2] - if v.Cursor == nextOne { + lastOne := v.Buf.cursors[end-1] + if v.Cursor == lastOne { if usePlugin && !PreActionCall("RemoveMultiCursor", v) { return false } - if end > 1 { - v.Buf.cursors[end-1] = nil - v.Buf.cursors = v.Buf.cursors[:end-1] - v.Buf.UpdateCursors() - } + v.Buf.cursors[end-1] = nil + v.Buf.cursors = v.Buf.cursors[:end-1] + v.Buf.UpdateCursors() v.Relocate() if usePlugin { @@ -1942,7 +1940,7 @@ func (v *View) RemoveMultiCursor(usePlugin bool) bool { // RemoveAllMultiCursors removes all cursors except the base cursor func (v *View) RemoveAllMultiCursors(usePlugin bool) bool { - if v.Cursor == &v.Buf.Cursor { + if v.Cursor == v.Buf.cursors[len(v.Buf.cursors)-1] { if usePlugin && !PreActionCall("RemoveAllMultiCursors", v) { return false } diff --git a/cmd/micro/buffer.go b/cmd/micro/buffer.go index 7f08acd5..6471baf0 100644 --- a/cmd/micro/buffer.go +++ b/cmd/micro/buffer.go @@ -309,6 +309,24 @@ func (b *Buffer) Update() { b.NumLines = len(b.lines) } +func (b *Buffer) MergeCursors() { + var cursors []*Cursor + for i := 0; i < len(b.cursors); i++ { + c1 := b.cursors[i] + if c1 != nil { + for j := 0; j < len(b.cursors); j++ { + c2 := b.cursors[j] + if i != j && c1.Loc == c2.Loc { + b.cursors[j] = nil + } + } + cursors = append(cursors, c1) + } + } + + b.cursors = cursors +} + func (b *Buffer) UpdateCursors() { for i, c := range b.cursors { c.Num = i diff --git a/cmd/micro/view.go b/cmd/micro/view.go index 72380093..fc27539c 100644 --- a/cmd/micro/view.go +++ b/cmd/micro/view.go @@ -511,6 +511,7 @@ func (v *View) HandleEvent(event tcell.Event) { relocate = v.ExecuteActions(actions) || relocate } v.SetCursor(&v.Buf.Cursor) + v.Buf.MergeCursors() break } } @@ -571,6 +572,7 @@ func (v *View) HandleEvent(event tcell.Event) { relocate = v.ExecuteActions(actions) || relocate } v.SetCursor(&v.Buf.Cursor) + v.Buf.MergeCursors() } }