TEXTAREA undo, why is it so inconsistent?

  • Banned

    Continuing the discussion from Feature Request: Multiple selection of categories:

    @error said:


    Undecorated: type a few words, paste from clipboard, type a few words
    <kbd>CTRL</kbd>-<kbd>Z</kbd> 1x: deletes last few words
    <kbd>CTRL</kbd>-<kbd>Z</kbd> 2x: deletes pasted text
    <kbd>CTRL</kbd>-<kbd>Z</kbd> 3x: deletes first few words

    Discourse: same procedure
    <kbd>CTRL</kbd>-<kbd>Z</kbd> 1x: deletes whole line

    We have this custom crazy-ass logic in our composer that implements undo. I wanted to explain why, cause it does make me feel pretty confused.

    Take http://codepen.io/anon/pen/uryJl

    In all browsers:

    Type in

    test line one
    test line two
    test line three

    Press CTRLZ

    All 3 lines are gone, so all 3 major browsers get 1 silver WTF.

    But IE gets the Gold WTF

    Type in a paragraph, hit backspace, type in a second paragraph.

    In Firefox and Chrome, undo will take you to the point where you hit backspace.

    In IE, it will just delete all content.

    To add to the general WTF of this, generally browsers implement CTRLR as "reload" (and use CTRL SHIFT Z for redo) so getting to a state where you destroy your work is trivial.

    Note: the best implementation seems to be Firefox, as it handles intermediate states more gracefully

  • Banned

    In the below examples, I type three lines:

    I type some stuff

    I type some more stuff

    I type even more stuff

    Here's how I type it:

    • type a little
    • pause for a while, change window focus
    • type a little more
    • pause for a while
    • type a little more
    • pause
    • press ctrl+z

    When I type and then pause, I indeed get proper native browser undo/redo in chrome, in the textbox:

    As you can see, @sam, it did not undo all the typing, just to the last pause point.

    Here's me testing in IE11:

    Same pattern as above -- typing, pausing, shift focus, type more, etc.

    The default textarea browser undo really seems fine (and works as expected with paste, paste creates an undo point), I don't want all this complex, fragile extra code in the editor to support "manual" undo and redo.

  • Banned

    I am totally not following, if I start typing, and just type and type and type and type...

    Like I normally do when I am authoring a post I get 1 restore point, that's it. Compare that to say, something sane like word.

  • @sam said:

    Compare that to say, something sane like word.

    I am curious to know what Word does...
    Creating undo checkpoints only when the text insertion is paused makes sense IMO: “Undo” undo an action, and typing a wall of text is a single action. If you pause typing and get back to your text later, it’s a new action and it should get a new undo checkpoint.

    I’m guessing you expect a checkpoint to be created on every typed line. Why? Why would I want to remove the last line I have typed? If it is incorrect, I can just correct it directly, no need to retype everything. Also, undo checkpoints consume memory, and they sometimes are limited in number. Better not generate too many of them.

    I’m also pretty sure that messing with undo/redo will cause browser-specific bugs.


  • test one@sam said:

    All 3 lines are gone, so all 3 major browsers get 1 silver WTF.

    Opera undoes line by line, but there are other problems - paste randomly doesn't work, and if editor doesn't have focus, clicking in it scrolls up, and places the cursor away from where you clicked.

  • @VinDuv said:

    I’m also pretty sure that messing with undo/redo will cause browser-specific bugs.

    Plus, if you're actually familiar with and used to the way your browser works, messing with the behaviour is really annoying.

    Also: the undo-redo is broken when copy-pasting with middle-click. For instance, in a normal text area, doing the following:

    1. type text
    2. paste (middle click)
    3. ctrl-z

    will remove the text from (2.). Here, it'll remove the text from (1)+(2).

    Ctrl-v + ctrl-z is even weirder, and it's somewhat hard to pin down the behaviour. Example:

    • type text (last line in above paragraph): "... text from (1)+(2)."
    • paste word ("browser"): "... text from (1)+(2).browser"
    • press ctrl-z: "... text from (1)+2(2."

    (I could repro that a couple of times, then I typed up the text above, and now it does something different, but still wrong.)

    Filed under: [I fucked up this post's contents a couple of times with ctrl-z](#tag)

  • @VinDuv said:

    I am curious to know what Word does...

    Word creates an undo point for every word typed, and one for every character of the last few words.

    But if you are concerned with memory usage, well, get a 386 or something better.

  • Discourse touched me in a no-no place

    @Mcoder said:

    Word creates an undo point for every word typed, and one for every character of the last few words.

    It's a bit more complicated than that. Conceptually, word keeps a pair of stacks of actions which may be undone and redone; undoing an action pops it off the undo stack and pushes it on the redo stack (as well as invoking the implementation of the undo) and redo is vice versa.

    No, it's a lot more complicated than that. Some actions (those relating to a continuous sequence of inserts or deletes, and maybe certain types of style changes too; I don't fully understand the compounding conditions) will gradually get rolled up into compound actions; go far enough back, and entire paragraphs will be compounded, and possibly even groups of the basic classes of edits — inserts, deletes and style changes — instead of just the single edit type. I can't remember if cuts and pastes ever get compounded. Finally, some actions (e.g., manually-triggered save) clear both stacks.

    Which sounds rather simpler than it is. (Why yes, I do maintain a GUI toolkit that implements an undo/redo system, though that's a part of the code I try to avoid reading.)

Log in to reply

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.