Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: fix merging of undo events



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



Messages sorted by: Reverse Date, Date, Thread, Author