[v3] Select restored fragment upon undo / redo #923
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Select fragment of the text, Hit Delete, Hit Undo
Expected:
Actual:
All the editors I've been using are doing what is expected.
Which editors have you been using? I just tried several (chrome textarea, firefox textarea, chome url bar, firefox url bar, emacs, gedit) and none behaves in this way.
Eclipse, Sublime, TextMate, Notepad, textarea I am currently typing in right now and virtually any editor?
Must be some Windows tradition I'm not aware of.
I doubt though that they always select all the text that's modified by the undo. That sounds like it'd be a pain. Don't they just restore the cursor/selection position that was current when the history event was saved? That sounds like it might be a good approach.
This behavior occurs in Firefox and Chrome for Linux as well (see jankeromnes's answer for more detail).
Personally, I think restoring the cursor/selection position from before the history event is the most user-friendly, but that may just be me.
I did some tests in Linux (Kubuntu). I found the results somewhat surprising:
Never select restored text upon Undo:
Only select restored text if it was selected before Undo:
Always select restored text upon Undo:
You must be using a different Chrome and Firefox then. Or maybe it's some deep GTK setting they are obeying that is set differently on my system.
Firefox 16.02 and Chrome 22 on Ubuntu 12.04, if that helps you narrow it down.
I've added functionality where it reverts to the selection that was present when the undoable changeset was saved. That's as far as I'm willing to go. (Selecting precisely the changed text is problematic, firstly because undo events may affect multiple stretches of text when those were changed in a single operation, and secondly because I'm not currently tracking the precise start and end of the changes, and it'd require an overhaul and a more expensive data model for the changesets to keep that information.)
What you've done is good, but I don't think it is good enough:
Side note: I don't think one should compare undo/redo behavior with the one in browsers, I'd rather target code editors. Popular ones I listed above seem to be consistent in this regard.
Can you provide a precise scenario in which it doesn't work as expected? I can't get the thing you describe to happen.
(Might be that
1cbf1f6400accidentally fixed it.)The one I described is now fixed, there is one remaining though:
Selection is restored when undoing just fine, but cursor is not moved to after "a" upon redo.
See attached patch. I think that should make it behave as you intend -- when redoing, the selection is reset to the point where it was when the action was initially done.
mentioned in issue #1038