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

Open
titoBouzout opened this issue Feb 25, 2016 · 1 comment
Open

get_regions does not work after undo or redo #1121

titoBouzout opened this issue Feb 25, 2016 · 1 comment

Comments

@titoBouzout
Copy link
Collaborator

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

    v.run_command('undo')

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

When the API does not work we have to resort to very ugly and not efficient hacks. See https://dl.dropboxusercontent.com/u/9303546/SublimeText/commands/undo_or_redo_without_moving_cursor_listener.py and https://forum.sublimetext.com/t/undo-and-redo-to-not-move-the-cursor/17988/4?u=tito

@ehuss

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