zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: fix merging of undo events
@ 2014-11-05 17:27 Oliver Kiddle
  0 siblings, 0 replies; only message in thread
From: Oliver Kiddle @ 2014-11-05 17:27 UTC (permalink / raw)
  To: Zsh workers

This fixes an issue that I introduced earlier this year in 32314.

It looked at the first undo event to get an undo change number for the
point where change merging should stop. By doing and undoing further
changes, this could have the effect of merging the current event onto
the previous changes.

If the new test case is run in a debugger, the final vi change is at
7, 8 corresponds to a change that has been undone and freed and 9 is
the new change (current->changeno in mergeundo()). So 9>7+1 is true and
change 9 got merged onto 7. Fortunately I had kept my gdb macro for
printing the undo stack.

The fix here is to use the undo_changeno value instead. Up to now that
was declared static.

Oliver

diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c
index 741f119..e95a34b 100644
--- a/Src/Zle/zle_utils.c
+++ b/Src/Zle/zle_utils.c
@@ -1395,7 +1395,8 @@ static struct change *nextchanges, *endnextchanges;
 
 /* incremented to provide a unique change number */
 
-static zlong undo_changeno;
+/**/
+zlong undo_changeno;
 
 /* If non-zero, the last increment to undo_changeno was for the variable */
 
@@ -1668,8 +1669,7 @@ splitundo(char **args)
 {
     if (vistartchange >= 0) {
 	mergeundo();
-	vistartchange = (curchange && curchange->prev) ?
-	    curchange->prev->changeno : 0;
+	vistartchange = undo_changeno;
     }
     handleundo();
     return 0;
diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c
index 18c76f9..d74b40d 100644
--- a/Src/Zle/zle_vi.c
+++ b/Src/Zle/zle_vi.c
@@ -109,7 +109,7 @@ startvitext(int im)
 {
     startvichange(im);
     selectkeymap("main", 1);
-    vistartchange = (curchange && curchange->prev) ? curchange->prev->changeno : 0;
+    vistartchange = undo_changeno;
     viinsbegin = zlecs;
 }
 
@@ -403,7 +403,7 @@ vichange(UNUSED(char **args))
 	forekill(c2 - zlecs, CUT_RAW);
 	selectkeymap("main", 1);
 	viinsbegin = zlecs;
-	vistartchange = (curchange && curchange->prev) ? curchange->prev->changeno : 0;
+	vistartchange = undo_changeno;
     }
     return ret;
 }
diff --git a/Test/X02zlevi.ztst b/Test/X02zlevi.ztst
index f8a94ce..561a5fd 100644
--- a/Test/X02zlevi.ztst
+++ b/Test/X02zlevi.ztst
@@ -207,6 +207,12 @@
 >BUFFER: pre
 >CURSOR: 2
 
+  zletest $'two\eOone\eo\euo\eu'
+0:undo starting with a next change in the change list
+>BUFFER: one
+>two
+>CURSOR: 2
+
   zpty_run 'bindkey "^Gu" split-undo'
   zletest $'one\C-gutwo\eu'
 0:split the undo sequence


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-11-05 17:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-05 17:27 PATCH: fix merging of undo events Oliver Kiddle

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).