Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_regions does not work after undo or redo #1121

titoBouzout opened this issue Feb 25, 2016 · 1 comment

get_regions does not work after undo or redo #1121

titoBouzout opened this issue Feb 25, 2016 · 1 comment


Copy link

@titoBouzout titoBouzout commented Feb 25, 2016

In theory the following should work, but after doing undo or redo the regions disappears.

    v = sublime.active_window().active_view()
    r = [sublime.Region(s.a, s.b) for s in v.sel()]

    if r:
        print('see regions has something: '+str(r))

    v.add_regions('r', r) 

    r = v.get_regions('r')
    if r:
        print('see regions has something: '+str(r))


    r = v.get_regions('r') # this should work, but it doesn't
    if not r:

When the API does not work we have to resort to very ugly and not efficient hacks. See and


This comment has been minimized.

Copy link

@ehuss ehuss commented Feb 27, 2018

I'm running into similar problems. In general, add_regions() and erase_regions() seem to get associated with the most recent edit (even if it 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.

Example where this is weird:

  1. Open a file and make some edits somewhere.
  2. Go somewhere else in the file and add a bookmark.
  3. Return to the edit you made in 1 and decide you don't want it anymore, so hit Undo.
  4. The bookmark added in 2 is now mysteriously gone. If it was in an area scrolled offscreen, you won't even see that it has disappeared.

In my use case, I am creating regions with unique keys, and I am tracking these keys in my plugin. When I erase all the regions (and stop tracking the keys), and the user presses undo, the regions return from the grave. Since my plugin is no longer tracking them, the user doesn't have an obvious way to dismiss the zombie regions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.