Sublime Forum

Add_regions/erase_regions and undo history

#1

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?

0 Likes

#2

hmm, where are you calling these methods from? maybe you need to call them from inside a TextCommand for best results

2 Likes

#3

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).

0 Likes

#4

Running into the same issue. Any news on this?

0 Likes

#5

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?

0 Likes

#6

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.

0 Likes

#7

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.

0 Likes

#8

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.

0 Likes