mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-07 07:30:20 +09:00
Clear cursors before performing undo or redo
This fix isn't ideal because it removes the cursors but it does work Fixes #798
This commit is contained in:
@@ -996,6 +996,10 @@ func (v *View) Undo(usePlugin bool) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if v.Buf.curCursor == 0 {
|
||||
v.Buf.clearCursors()
|
||||
}
|
||||
|
||||
v.Buf.Undo()
|
||||
messenger.Message("Undid action")
|
||||
|
||||
@@ -1011,6 +1015,10 @@ func (v *View) Redo(usePlugin bool) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if v.Buf.curCursor == 0 {
|
||||
v.Buf.clearCursors()
|
||||
}
|
||||
|
||||
v.Buf.Redo()
|
||||
messenger.Message("Redid action")
|
||||
|
||||
@@ -2028,12 +2036,7 @@ func (v *View) RemoveAllMultiCursors(usePlugin bool) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
for i := 1; i < len(v.Buf.cursors); i++ {
|
||||
v.Buf.cursors[i] = nil
|
||||
}
|
||||
v.Buf.cursors = v.Buf.cursors[:1]
|
||||
v.Buf.UpdateCursors()
|
||||
v.Cursor.ResetSelection()
|
||||
v.Buf.clearCursors()
|
||||
v.Relocate()
|
||||
|
||||
if usePlugin {
|
||||
|
||||
@@ -562,3 +562,12 @@ func (b *Buffer) ClearMatches() {
|
||||
b.SetState(i, nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Buffer) clearCursors() {
|
||||
for i := 1; i < len(b.cursors); i++ {
|
||||
b.cursors[i] = nil
|
||||
}
|
||||
b.cursors = b.cursors[:1]
|
||||
b.UpdateCursors()
|
||||
b.Cursor.ResetSelection()
|
||||
}
|
||||
|
||||
@@ -479,9 +479,14 @@ func (v *View) ExecuteActions(actions []func(*View, bool) bool) bool {
|
||||
return relocate
|
||||
}
|
||||
|
||||
func (v *View) SetCursor(c *Cursor) {
|
||||
func (v *View) SetCursor(c *Cursor) bool {
|
||||
if c == nil {
|
||||
return false
|
||||
}
|
||||
v.Cursor = c
|
||||
v.Buf.curCursor = c.Num
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// HandleEvent handles an event passed by the main loop
|
||||
@@ -505,7 +510,10 @@ func (v *View) HandleEvent(event tcell.Event) {
|
||||
}
|
||||
if e.Modifiers() == key.modifiers {
|
||||
for _, c := range v.Buf.cursors {
|
||||
v.SetCursor(c)
|
||||
ok := v.SetCursor(c)
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
relocate = false
|
||||
isBinding = true
|
||||
relocate = v.ExecuteActions(actions) || relocate
|
||||
@@ -553,7 +561,6 @@ func (v *View) HandleEvent(event tcell.Event) {
|
||||
for _, c := range v.Buf.cursors {
|
||||
v.SetCursor(c)
|
||||
v.paste(e.Text())
|
||||
|
||||
}
|
||||
v.SetCursor(&v.Buf.Cursor)
|
||||
|
||||
@@ -568,7 +575,10 @@ func (v *View) HandleEvent(event tcell.Event) {
|
||||
for key, actions := range bindings {
|
||||
if button == key.buttons && e.Modifiers() == key.modifiers {
|
||||
for _, c := range v.Buf.cursors {
|
||||
v.SetCursor(c)
|
||||
ok := v.SetCursor(c)
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
relocate = v.ExecuteActions(actions) || relocate
|
||||
}
|
||||
v.SetCursor(&v.Buf.Cursor)
|
||||
|
||||
Reference in New Issue
Block a user