How to turn off cmd-Z (undo) jumping around the file to the previous cursor position.
Answered
When we use cmd-z, the IDE immediate places the cursor back to it's location before the last change was made.
It's incredibly difficult to see the change made without spending time to find where the undo action happened.
Is there any way to turn off this behavior?
Please sign in to leave a comment.
Hello,
Do I get it right that you want to execute Undo operation immediately instead of doing it twice (Undo for moving caret, then undo for undoing changes)? Could you please share an example of what you are talking about?
Thank you.
I am having the same problem, to explain this further here is a scenario:
1) A code say; 10 pages long, on page-5 it has:
AAAAAAAAAAAAA
BBBBBBBBBb
CCCCCCCCCC
2) I scroll to page-3, do a normal copy-paste, edit stuff, or any editing...
3) I scroll up to page-5, select the BBBBBBBB line and then paste XXXXXXXXXXXX to replace it.
4) As expected, page-5 would end up having:
AAAAAAAAA
XXXXXXXXX
CCCCCCCC
5) Whilst looking at page-5, Press CTRL_Z (or CMD_Z) to UNDO. For some strange reason IntelliJ jumps back to Page-3, I totally lose track of what exactly was UNDONE.
6) If I try to CTRL_Y or CMD_Y to REDO, it takes me back to page-5, but then pressing UNDO again does not show me what's been undone, just jumps to another page which is incredibly confusing and difficult to work with
------------
The question is, how can we UNDO the content of a page (Page-5 in this example) without the system jumping to another page?
Thanks
Heider
Hi Heider,
Thanks for sharing.
Unfortunately, it is not available at the moment. Please see and follow IDEA-208735.
Hi Daniil,
IDEA-208735 is about a different thing, I believe. What it describes: type some text, move cursor, press Ctrl-Z - cursor moves back, text is not undone though. Second Ctrl-Z is needed for that.
What Heider describes (and what made me find this thread): move cursor, type some text, press Ctrl-Z - text is undone and cursor immediately moves back where it was initially. I would expect the first Ctrl-Z to undo typed/changed text, cursor doesn't move anywhere. And then second Ctrl-Z moves cursor where it was initially.
As was mentioned, if this cursor jump happened not within the same viewport (window had to be scrolled to perform it), you can't see the result of your Ctrl-Z. Maybe I renamed a var, returned old name back and now I want to copy that old name in my clipboard? Sometimes it can be hard to even find the place you've just Ctrl-Zetted.
Btw, behavior in IDEA-208735 is totally fine in my opinion. If text would be undone immediately, it would create the same problem - if your cursor was jumping not from the current viewport, you wouldn't see what just changed.
Hi Skaurus,
Thanks for sharing.
Feel free to create a new ticket on our issue tracker to support this workflow as well: https://youtrack.jetbrains.com/issues/IDEA
Skaurus did you create an issue? If so can you link it?
This undo behavior is truly annoying.
Fr4nk235 no, never got to it. Tried to create it now, but I can't actually reproduce this behavior, using plain text or Go scratch files 🥲
Here is my draft, where actual behavior described and it is working as I would expect:
This ticket is closely related to https://youtrack.jetbrains.com/issue/IJPL-28593/Expose-Undo-undoes-navigation-cursor-position-as-a-user-configuration-option but with an important addition(s).
While I can appreciate that pressing Ctrl-Z twice seems excessive within a viewport, it is absolutely not when the change area and previous caret position are in different viewports (you can't see both places without scrolling a window).
Imagine having your caret somewhere in a long file. Then you scroll to a different place a few screens away and change something. Then you decide against it and press Ctrl-Z. Caret immediately jumps to the first position, leaving you no chance to see what has changed. Arguably, it changed to what was before, do you really need to see it? But maybe your change involved renaming some method, and then you canceled that change, but you also need to copy its name in a buffer to call it elsewhere? Now you will have to look for this place manually to do it.
Also, personally, I would prefer to see the final state of the code with my own eyes before jumping anywhere, it helps me keep mental track of it.
Also, this behavior is actually different for Ctrl-Z (undo) and Ctrl-Shift-Z (redo), at least in GoLand 2024.3.
Same viewport, Ctrl-Z (typed/changed some text, moved a caret within the same viewport, pressed Ctrl-Z):
caret moves back; second Ctrl-Z needed to actually undo the change
Same viewport, Ctrl-Shift-Z (typed/changed some text, Ctrl-Z, moved a caret within the same viewport, pressed Ctrl-Shift-Z):
caret moves back; second Ctrl-Shift-Z needed to actually redo the change
Different viewports, Ctrl-Z (typed/changed some text, moved a caret to a different viewport, far enough away so it can't be displayed at the same viewport as with the changed text, pressed Ctrl-Z):
caret moves back; second Ctrl-Z needed to actually undo the change
Different viewports, Ctrl-Shift-Z (typed/changed some text, Ctrl-Z, moved a caret to a different viewport, far enough away so it can't be displayed at the same viewport as with the changed text, pressed Ctrl-Z):
caret moves back; second Ctrl-Z needed to actually undo the change
Hi Fr4nk235 and Skaurus !
Please feel free to create a feature request as per my colleague's suggestion. We'll be happy to look into this and see if it can be implemented.