ISE Undo location?

When I come back to ISE after looking at something else, getting food, using restroom, etc., I find the file I was working on (in the scripting pane) is not saved. I want to see what the last thing I modified was because sometimes, it’s just a random character my cat/child/self hit on the keyboard. In many editors, when you hit undo/redo, it jumps to that point in the code and it’s easy to see the change that it’s (un)making.

Even with ISE, when your cursor is not within the viewing window and you type something, it jumps to the changed line. However, this does not appear to be the case when using Undo/Redo. If the changed line is not actively within the viewing window, you see no change when using Undo/Redo. In a 1500+ line script, having to do Ctrl+Z, Ctrl+Y over and over again as you scroll down the file, hoping to visually see the change is not really an efficient approach. Nor is saving as a new file and diffing the new and old and deleting the undesired. Is there any option or setting or something that can get ISE to follow the “jump to change/cursor” action it uses when typing at a cursor location off the viewing screen, for Undo/Redo as well? Or some way to easily/quickly identify the location of a change?

EDIT: Clarified I’m working in the Scripting Pane

Edit2: Looks like this is a feature request: https://windowsserver.uservoice.com/forums/301869-powershell/suggestions/11087958-windows-powershell-ise-caret-and-view-do-not-jump

1 Like

try get-history to see what happened last

edit: sorry i misread your OP. i thought you had entered a change and was looking for where, not changed something in the scripting pane of ISE and hadn’t executed it yet.

Mike, thanks. I edited the original for clarity.

Solution (workaround) shown below…

This problem has bugged me for years - it seems unbelievable it wasn’t fixed before as it’s a bit of a fundamental editing requirement! A bug in PowerShell ISE means that most of the time Ctrl Z won’t jump the cursor to the last edited position. If you have scrolled since the change it can be quite time consuming to work out what you are undoing - making it almost impossible to go back far.

Just as you said, I’ve often had to save a temporary version of the file, use WINDIFF to find what was changed and where I had accidentally started typing when the cursor unintentionally jumped. Yet once in a while I found it was actually working.

Recently I spent some time experimenting to find when it does and doesn’t work; at last I found a solution and this leads to a useful workaround. I found that Edit Undo/Redo always works correctly when using a NEW tab in Powershell ISE - but it never works after opening an existing file.

So a workaround is simply to copy the contents of an existing file - paste it into a new tab - and than save it back on top of the existing file! You can now edit, and undo (and redo) works perfectly, with the cursor jumping to the previous locations. As long as you keep this file open, you can develop, test, and save as often as required and Edit, Undo (CrrlZ) /Redo (Ctrl Y)
will continue to work perfectly. Each time you open an existing file, you need to apply the workaround - which only takes a few seconds. While it seems crazy to have to do this, it’s well worth it.

Here are the steps in detail
Open your file,
mouse click within the script area,
Ctrl-A to select All,
Ctrl-C to copy the contents to the clipboard
Ctrl-F4 to close the tab,
Ctrl-N to open new tab,
mouse- click in the empty script,
Ctrl-V to paste the clipboard contents
Ctrl-S to save
Select the file name you just copied - save on top of that file (or save with a new name if desired perhaps incrementing the version number)

You can now continue developing and testing your script and the cursor / caret will now successfully jump to the changed text each time you press Ctrl-Z to undo or Ctrl-Y to redo.