Subject: Re: bug#21523: 25.0.50; Undo with active region adds extra text

From: Stefan Monnier <[email-masked]>
Date: Sun, 20 Sep 2015 11:14:29 -0400

> `C-_' to undo the last change within the region.
> The word "that" is inserted, giving this:
>   ;; then enter the text in Thatthat file's own buffer.
> This seems disconcerting, at least.  (Same behavior for `M-u' etc.)

Indeed, that's wrong.  I haven't looked in detail of why this happens,
but I can guess that it's because the previous change is represented as
"insert That" and "remove that", and when we undo them, the exact
location of "remove that" ends up right at the region boundary, making
it unclear whether it should be considered as "inside" or "outside".

Not sure how best to fix it.  Maybe such replacements should have
a special status in the undo-list, so they aren't considered as
two independent changes (remove+insert) but as a single one.

Or maybe the "undo-in-region" should only ever undo complete steps
(i.e. everything between two undo boundaries), so if any part of an undo
step affects text outside of the region, then the whole step is skipped.

        Stefan