Powershell ISE Undo Caret Location

Occasional Visitor

When editing files in the Scripting Pane in PowerShell ISE, most of the time when you use Edit/Undo by pressing Ctrl Z, it FAILS to scroll the script to the location that has just changed. The cursor (caret) fails to jump to the edit undo location - yet the Undo action does actually work.

This makes it impossible to see what you have just undone if it's off the page.  You might want to work backwards to see what you just recently changed - or it might be due to an unintentional deletion due to accidental selection and overtype because of a sensitive touchpad .  Whatever the reason, it's very time consuming to scroll around, pressing Ctrl Z and Ctrl Y alternately to Undo/Redo in order to work out where the change was - and if you can't find it, you may have undone too much and you aren't going to know until later!   All other editors, VS Code, Notepad++, Textpad etc  (and Word processors) will jump to the location being undone/redone.


However, it does work successfully for a new tab - including after you have saved a file.  This means you could actually work around the problem by always opening a new tab, copying and pasting in the contents of an existing powershell script, file saving and overwriting the same powershell script - then continue working;  now Edit Undo/Redo will successfully jump the scroll position of the file perfectly - and you can edit, debug,save as much as you like. It just goes wrong again when you open the file in the normal way, as a new tab into ISE ! 

However, PowerShell ISE just will not do this - it's a long-standing bug and of course ISE is now no longer supported.  However someone may have found a setting to fix this ?


As we do more work on laptops these days, we encounter the frequent problem of accidentally selecting text due to sensitive touchpad, more often than before, resulting in accidental deletion of a section of code and continuing to type in another area!. That makes needing to use Undo more often than you'd hope - and has added up to a lot of time wasted searching for the text to undo while coding with PowerShell ISE. Sometimes I've had to save and compare with a previous version, wasting even more time to manually undo unwanted edits.  Yes I know I could use VSCode but ISE is my preference (which isn't too difficult to use with Powershell 6/7 either)  and I'm hoping someone might know a setting or perhaps could script the workaround that does this:

  Open desired script
  Ctrl A to select entire contents
  Ctrl C to copy selection
  Ctrl F4 to close window
  Ctrl N to Create new tab
  Ctrl V to paste Clipboard Contents
  Ctrl S to save - save and overwrite the filename)


The above workaround does enable correct caret positioning for Edit Undo/Redo within ISE because the existing file hasn't been opened into a new tab and instead was pasted into an untitled tab and saved.    It would be really handy if this could be scripted to replace the File Open dialogue or something along those lines.


Many thanks


0 Replies