66

I haven't been able to find another question about this but it would surprise me if no one ever wrote one, because it is so annoying. Also I'm not sure which tag to use because I cannot honestly tell if the current behavior is a bug or a feature.

So, okay, the text editor has its critics, it is not meant to be exactly an IDE but more of a paste-your-code-here box. Still, I cannot understand why the undo (Ctrl+Z) operation is so purposefully annoying. Here is something that has happened to me a number of times already:

  1. I write some text.
  2. I paste a piece of code and format it.
  3. I realize I need to make a couple of changes before posting it (e.g. rename a variable, remove a printing statement, etc.)
  4. I make a mistake while doing one of these small changes, so I press Ctrl+Z (this is muscle memory for me, which makes the next point extra annoying).
  5. Instead of undoing the last small change I did, all the code that I pasted and some of the text I wrote before disappears.

The worse part about this is that it has somehow intentionally been designed like that, because native browser undo/redo implementations (thankfully) do not work that way (breaking my expectations about the behavior of the action). The behavior is the same in the search text box but, interestingly, not in the question title text box, it seems.

Has anyone else noticed this?

I have tested this on Chrome and Firefox by the way.

Update:

I have made made a couple of screencasts showing this. Here is the behavior in an answer text box (similar in questions and search):

Undo in answer text box

I write a bunch of stuff, press Ctrl+Z (note the "Redo" button gets active) and everything is gone. You can actually write way more but I think it is already clear.

For comparison, here is the behavior in comment boxes, which matches my expectation:

Undo in comment text box

Here, each time I press undo only a few characters are removed.

15
  • 14
    This happens to me as well. I'll hit CTRL+Z to undo a single paste and half my post disappears. Lately I've just developed the habit to highlight and delete then undoing. Aug 18, 2017 at 12:32
  • 3
    This specific issue has been adressed on Meta.SE: Editor's undo does not track pastes and CUT & Paste are not considered undoable operations. No solutions though.
    – Jan Doggen
    Aug 18, 2017 at 13:15
  • 2
    @JanDoggen That looks like a different issue also related to undo (it also happens when I write a long text block). The question Ctrl+Z undoes twice in editor seems more similar, although the behavior I see is not exactly that (it goes beyond two modifications many times), and An option to disable the editor's undo/redo feature seems to go along the same lines...
    – jdehesa
    Aug 18, 2017 at 13:19
  • 6
    I've never seen it done differently in web-based text editors, but maybe don't get out enough. Instead of an elaborate undo stack that requires an inverse command for every single edit operation, they take the simple shortcut. A timer makes a copy of the entire textarea. Undo is now a simple restore. So how much you lose depends on how fast you type. I always, always use my programming editor to produce code samples. Syntax errors and code that just doesn't do what it promises are too embarrassing. Aug 18, 2017 at 14:54
  • 5
    @HansPassant I could understand that (to an extent) if it were a WYSIWYG editor or sth, but I mean it's a textbox with convenience buttons (and a preview). I don't want a fancy implementation, just the default behavior of every other textbox (e.g. the one where I'm writing this comment now). I type relatively fast, and sometimes I mistype something (not just code) and quickly press Ctrl+Z and go on, and this destroys half of my post (can't redo if I typed something else). Idk, if we're just not supposed to make a single mistake in the text box then don't provide an undo operation at all.
    – jdehesa
    Aug 18, 2017 at 15:09
  • I'm still surprised it's not just a standard markdown editor at this point.
    – Jon Shier
    Aug 19, 2017 at 4:48
  • 2
    What's interesting about this is that SO is not the only web-app I know that's particularly Ctrl-Z hungry. Google's stuff tends to have unfortunate Ctrl-Z behavior too. Aug 19, 2017 at 5:11
  • Isn't Shft-Ctrl-Z = redo? (not saying the bug shouldn't be fixed just saying maybe you can recover)
    – gman
    Aug 19, 2017 at 9:25
  • 1
    @gman Yes, you are right, you can redo. Although it is annoying that you have to either rewrite part of what you wrote or manually select what you want to delete... And if you do Ctrl+Z and type something (unintenionally or because you're writing fast) then there's no coming back.
    – jdehesa
    Aug 19, 2017 at 12:18
  • I am fairly certain that this is behavior defined by the browser, not by Stack Overflow. It works the way @HansPassant outlined, I believe. Now, one could argue that Stack Overflow should implement their own editor that does have a stack of edit operations, overriding the built-in Ctrl+Z shortcut... I'm on the fence on that one. Aug 21, 2017 at 6:51
  • @Justastudent No, Stack Overflow definitely has some custom undo/redo implementation in their question/answer/search boxes. The behavior in the comment boxes, on the other hand, is the standard browser-defined one. However, like Nicol Bolas said, SO is not the only website doing this; I've seen for example something similar in GitHub issues text boxes. Maybe it's not something done by SE directly, but rather some underlying common component.
    – jdehesa
    Aug 21, 2017 at 8:56
  • @jdehesa Honestly, I don't see a difference between the various boxes. That may just be me though, or Firefox. How can I test this? Aug 21, 2017 at 19:42
  • @Justastudent I have added a couple of screencasts showing the behavior in a question/answer text box and in a comment one.
    – jdehesa
    Aug 22, 2017 at 9:12
  • @jdehesa That clears everything up, thank you so much. Aug 22, 2017 at 10:05
  • 1
    Seems sad that a site founded by two guys that ran famous blogs on code quality that these bugs still exist. Bit me again today. No recovery. Had to start over 🤬
    – gman
    Jun 20, 2020 at 16:11

0

You must log in to answer this question.

Browse other questions tagged .