Occasionally ⌘Z (undo) resets buffer to an old state and clears undo history (code is lost)


It happens rarely, but sometimes, when my fingers are coding faster than my brain, I hit something weird when trying to hit ⌘S (save a file) and the file looses it’s contents - the opened tab for the file is in the weird state now - ⌘Z (undo) doesn’t work anymore and I’ve lost the code I’ve just written, there’s no way to get it back. The best thing I can do now is to close the tab without saving it and the file seems to be in the version from after the last save (still I’ve lost the code I’ve written after last save until now).

Anyone experienced this problem (OSX)?


Is the file stored in Dropbox (or another similar service)?

Or are you using vim-mode?


Not using dropbox or anything like that, haven’t touched vim mode.

I should mention that developer tools opens, I’m pretty sure I’m triggering some weird key combination.

ps. I haven’t tried to recover the code with redo, I’ll try next time.


Ok … if you can get the stack trace from the developer tools, that would be a big help too.


So it happened twice since last time, this time after ⌘Z (undo) followed by (quickly) up-arrow or left-arrow.

There is a slight, fraction-of-a-second-long noticeable hang (maybe my HDD is waking up?) and it feels like ⌘Z is being registered several times during this hang (ps. I don’t have vim mode package installed).


Happened again. This time I’ve pressed ⌘Z only - nothing else and it travelled way, way back with the buffer being good few minutes before. This is very annoying and makes it hard to work with Atom. Do you think it’s related to packages use? I’m editing CoffeeScript file btw. Don’t have vim-mode or any linters installed.


Can you reproduce the issue after exiting Atom completely and then launching using atom --safe?


Can you redo? …


No I couldn’t redo, that’s one of the most annoying things. I’ve disabled most of the plugins and waiting for it to happen.


I suspect this might be caused by accidentally hitting Cmd+Alt+Z instead of Cmd+S or Cmd+Z. Cmd+Alt+Z is the default keybinding for editor:checkout-head-revision, which reverts your active file to whatever is checked in to Git. Try adding this to your keymap.cson:

'.workspace .editor:not(.mini)':
  'alt-cmd-z': 'unset!'

Or this if you’re on Windows or Linux:*

'.workspace .editor:not(.mini)':
  'ctrl-alt-z': 'unset!'

I suspect that Cmd+Alt+Z is just too easy to fat-finger when trying to undo something … and there’s no confirmation dialog. What is interesting is that you can’t Redo this action, but you can Undo it … which would be another confusing thing about it, since it is mapped to a modification of Undo by default … implying that it is a type of Undo.

I’ve opened an Issue on this here:

And now there’s a pull request to add a confirmation dialog here:

* Just adding this last bit for when I refer others to this post.

A seriously nasty problem

Should be 'ctrl-alt-z' for Windows/Linux.


Yeah, thanks … copy-paste error … fixed now.


BTW, that was a great catch @leedohm.


Thank you :grinning: It actually was a bit of a stretch for me for a couple reasons:

  1. I use the Dvorak keyboard layout … so my fat-finger patterns are different than most people’s fat-finger patterns :laughing:
  2. I use a utility called Alfred that captures the Cmd+Alt+Z key command before Atom gets it … so I can’t fat-finger this command on my machine

I just kind of stumbled on it because I was looking for the command right after reading this topic and saw the key combination in the Command Palette :laughing:


I’m old and shaky so I have fat fingers all the time. I’ve just about worn out my escape key.


@leedohm thanks for insight, it has to be something else unfortunately, cmd+alt+z works just fine, if i was fat fingering it i’d just undo it and carry on… but it’s something else. I’m really losing written code, there’s no way to undo/redo it. The only thing I can do is to close the tab without saving it and hope last saved version was not too far off. I’ll try to narrow it down a bit more…


Have you had it happen since you blocked that key binding?


I’ve thought about it and ctrl-shift-Z has to be the problem. I don’t have old versions anywhere in my system so it couldn’t go to an old version without getting it from the repo.

I have ctrl-shift-A mapped to something that goes to another tab. So my brain would expect things to change when pressed. And A is immediately next to Z.


Yes, just happended (with '.workspace .editor:not(.mini)': 'alt-cmd-z': 'unset!').

It’s pure cmd+z - I was still holding the keys, I know I didn’t hit anything else.

It happens in jade, coffeescript and golang contexts so it doesn’t seem to be related to any language.


Do you think it came from your repo?