Skip to content

Commit 3737979

Browse files
authored
Merge pull request zyedidia#3416 from dmaluka/undo-cursor-fix
Fix cursor moving to an unexpected location after a redo
2 parents be69b25 + 0d51035 commit 3737979

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

internal/buffer/eventhandler.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,9 @@ func (eh *EventHandler) UndoOneEvent() {
291291
eh.UndoTextEvent(t)
292292

293293
// Set the cursor in the right place
294-
teCursor := t.C
295-
if teCursor.Num >= 0 && teCursor.Num < len(eh.cursors) {
296-
t.C = *eh.cursors[teCursor.Num]
297-
eh.cursors[teCursor.Num].Goto(teCursor)
298-
eh.cursors[teCursor.Num].NewTrailingWsY = teCursor.NewTrailingWsY
299-
} else {
300-
teCursor.Num = -1
294+
if t.C.Num >= 0 && t.C.Num < len(eh.cursors) {
295+
eh.cursors[t.C.Num].Goto(t.C)
296+
eh.cursors[t.C.Num].NewTrailingWsY = t.C.NewTrailingWsY
301297
}
302298

303299
// Push it to the redo stack
@@ -336,13 +332,9 @@ func (eh *EventHandler) RedoOneEvent() {
336332
return
337333
}
338334

339-
teCursor := t.C
340-
if teCursor.Num >= 0 && teCursor.Num < len(eh.cursors) {
341-
t.C = *eh.cursors[teCursor.Num]
342-
eh.cursors[teCursor.Num].Goto(teCursor)
343-
eh.cursors[teCursor.Num].NewTrailingWsY = teCursor.NewTrailingWsY
344-
} else {
345-
teCursor.Num = -1
335+
if t.C.Num >= 0 && t.C.Num < len(eh.cursors) {
336+
eh.cursors[t.C.Num].Goto(t.C)
337+
eh.cursors[t.C.Num].NewTrailingWsY = t.C.NewTrailingWsY
346338
}
347339

348340
// Modifies the text event

0 commit comments

Comments
 (0)