Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,
	T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1464138178; bh=RKyhZzEctEsw0yRCcbLZKG5x76GzNM18b6zq+3uwmm4=; h=In-reply-to:From:References:To:Subject:Date:From:Subject; b=Db+eygDNzWVlpKnFs2v+l+xdKJpLawkdj1VXIpsEGUkHi/BDsHBPCmGMAs25fQK20SD+VtJBTV1PT80d+DdEJYk3oMbmAGE/Ljn8j00ri1s+h60a/AjA8GZaMVyADrDXY1rkZ+OJBMf2dD3nYf/CLVY4b/ejPHAoBwcU5X1VMtHMn1N1caWhJd6smvN3XChRdlOd0zbiOIDXdAiB1OGCxE4WUMhdLd7Z4GeZVdrF8Bhx0quJ1LzEkMjKsiUHq5hQoGPLSNisSAxqtmpRgwPHr0lswWx9nSV7xmtVTkw+r0ZWTVsHRA6ue/sYXLgfR2C+1NT/kkOXNf8nBEC6998Drg==
X-Yahoo-Newman-Id: 184842.78463.bm@smtp128.mail.ir2.yahoo.com
X-Yahoo-Newman-Property: ymail-3
X-YMail-OSG: IpV0H5AVM1m12v_vy_LLdJq8ojAE_r9azAzKVUXvaXDfrRY
 bKed.sRHvklHaJxhv4SmrvD5pUcgBfM7.yi6DVtGZsO6xgjxewyL2rP9aKj8
 joGsG9CEqMzts5.UEWUNDPyR5Uay9796cPRQbUIDsm.aPDn6rNyaKQt1bHEB
 B07PKjX8poXeNKtpfYVXdA1HmmKCtbxrrhrJ24oiSDyr_8HsjvGLFzJBsubV
 x0HvGNDWEM63hkp1QMqgzcMHYsznkAxaL02D0IQMxKQrr8PcJIEPeqNdj2.v
 WRmSBL8wG3a9GsevFEFm6iixllO.GJUR3qC_CngHyinlVKr6f9HBxqVp9iMN
 luCFKS46REwnExjcSbpd.udTfPHB.UxIqWnKlNIWzUoK8d4OqJF82VCy2.mT
 CUhZH2ze4eqOIH2gOPwXJ2IeQs5rUcT2HxfiIN62GVH5DmQoL3LhP3V8qIzn
 1eH0n2Q7RYlkbnq_oGQESnp2zjuKV.oJH0x.oEM2k68qiKsdMDTdY6dV.m_O
 OfX5wQuzXSgsGaulmcZ5s6_xpRnbB8Q--
X-Yahoo-SMTP: opAkk_CswBAce_kJ3nIPlH80cJI-
In-reply-to: <CAHYJk3TPHXFx96mm-40hvEqnd__8v8mnebiZ1r+thxGorZz=qg@mail.gmail.com>
From: Oliver Kiddle <okiddle@yahoo.co.uk>
References: <CAHYJk3TPHXFx96mm-40hvEqnd__8v8mnebiZ1r+thxGorZz=qg@mail.gmail.com>
To: zsh workers <zsh-workers@zsh.org>
Subject: Re: Bug in undo/redo handling in conjunction with history-beginning-search-backward
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <7786.1464138158.1@thecus.kiddle.eu>
Date: Wed, 25 May 2016 03:02:56 +0200
Message-ID: <7795.1464138176@thecus.kiddle.eu>
X-Seq: zsh-workers 38540

On 20 May, Mikael Magnusson wrote:
> % bindkey -e
> % bindkey '^U' undo
> % bindkey '^Y' redo
> % bindkey '^[C' history-beginning-search-backward
> at this point, type in "bin" and invoke the
> history-beginning-search-backward widget, type a space, then undo and
> redo fully a few times, you'll notice the point where the extra "n"
> starts popping into the command line.

On first attempt, I couldn't reproduce this. I do get the effect with
repeated undos and no redos, however.

The way history line changes are stored in the undo code differs
markedly from other changes. So the code has ended up with special logic
to handle the history changes.

36131 was when I last touched this and I wasn't really happy with the
state of things then but that was just before a two week holiday. At the
time, I said:
  It might be better to create full undo entries for history changes
  though that would need hacks to ensure that multiple history changes
  are undone in a single step.

If this patch doesn't do the job then that might be a better approach
than playing whack-a-mole with further issues.

Oliver

diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c
index 68794c6..80219a4 100644
--- a/Src/Zle/zle_utils.c
+++ b/Src/Zle/zle_utils.c
@@ -1589,9 +1589,14 @@ undo(char **args)
 	    break;
 	if (prev->changeno <= undo_limitno && !*args)
 	    return 1;
-	if (!unapplychange(prev) && last_change >= 0)
-	    unapplychange(prev);
-	curchange = prev;
+	if (!unapplychange(prev)) {
+	    if (last_change >= 0) {
+		unapplychange(prev);
+		curchange = prev;
+	    }
+	} else {
+	    curchange = prev;
+	}
     } while (last_change >= (zlong)0 || (curchange->flags & CH_PREV));
     setlastline();
     return 0;

