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

Re: zle: vi mode: wrong undo handling on fresh lines



This is my "trial" to (somewhat) improve the behavior of 'undo' after completion.
The patch below is against (git-HEAD)+(patch in 32314 by Oliver Kiddle).

The change in zle_tricky.c is to start a new undo-block when entering a
completion.

The change in zle_main.c is to make 'undo' no to bring back the suffix added
by completion but erased when going back to the command mode.
(This will also change the behavior in emacs-mode.)

Or these are just matter of preference and must not be hard-coded but
configurable?



diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index f5aec84..72650a8 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -1332,8 +1332,10 @@ execzlefunc(Thingy func, char **args, int set_bindk)
 	    eofsent = 1;
 	    ret = 1;
 	} else {
-	    if(!(wflags & ZLE_KEEPSUFFIX))
+	    if(!(wflags & ZLE_KEEPSUFFIX)) {
 		removesuffix();
+		handleundo();
+	    }
 	    if(!(wflags & ZLE_MENUCMP)) {
 		fixsuffix();
 		invalidatelist();
diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c
index 2689d0f..49dae8a 100644
--- a/Src/Zle/zle_tricky.c
+++ b/Src/Zle/zle_tricky.c
@@ -673,6 +673,9 @@ docomplete(int lst)
      * an emulation.                                                      */
     if (viinsbegin > ztrsub(zlemetaline + wb, zlemetaline))
 	viinsbegin = ztrsub(zlemetaline + wb, zlemetaline);
+    /* finish the current undo block and start a new one */
+    vimergeundo();
+    vistartchange = (curchange && curchange->prev) ? curchange->prev->changeno : 0;
     /* If we added chline to the line buffer, reset the original contents. */
     if (ol) {
 	zlemetacs -= chl;
diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c
index 9e9cc2f..e6c10a1 100644
--- a/Src/Zle/zle_vi.c
+++ b/Src/Zle/zle_vi.c
@@ -112,6 +112,19 @@ startvitext(int im)
 }
 
 /**/
+void
+vimergeundo(void)
+{
+    struct change *current = curchange->prev;
+    while (current && current->changeno > vistartchange+1) {
+	current->flags |= CH_PREV;
+	current = current->prev;
+	if (!current) break;
+	current->flags |= CH_NEXT;
+    }
+}
+
+/**/
 ZLE_INT_T
 vigetkey(void)
 {
@@ -584,13 +597,7 @@ vicmdmode(UNUSED(char **args))
 {
     if (invicmdmode() || selectkeymap("vicmd", 0))
 	return 1;
-    struct change *current = curchange->prev;
-    while (current && current->changeno > vistartchange+1) {
-	current->flags |= CH_PREV;
-	current = current->prev;
-	if (!current) break;
-	current->flags |= CH_NEXT;
-    }
+    vimergeundo();
     vichgflag = 0;
     if (zlecs != findbol())
 	DECCS();




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