add_regions()
and erase_regions()
have some odd interaction with the undo stack. They seem to be associated with the most recent edit in the undo stack (even if that edit had nothing to do with adding/removing the regions). For my use case, I would prefer that they don’t get added to the undo stack at all. Has anyone found a workaround to prevent these from being added to the undo history?
Add_regions/erase_regions and undo history
hmm, where are you calling these methods from? maybe you need to call them from inside a TextCommand
for best results
It happens whether it is in a TextCommand or not. In fact, the behavior is even more odd in a TextCommand because redo will not reinstate the change (outside of a TextCommand, it will).
add_regions
are not a part of the undo history. The only way they get removed is either through erase_regions
or when the relevant text is deleted (through undo or otherwise). Could you provide an example of the behavior you’re seeing?
Regions do get added to the undo history.
There are a few issues tracking this:
1121 contains repro steps using bookmarks. Type some text, add a bookmark somewhere else in the file, hit undo, and the bookmark disappears.
Huh, I was unaware of this functionality. Saving regions on the undo stack allows us to recover those when an undo is made, ie. the user erases the whole file then does undo. There is the NO_UNDO
flag if this behavior is not desired.
Oh, wow! So, I’m guessing this is a Sublime 4 thing? I can’t find any mention or documentation, and it is not mentioned in the changelog.