Home Download Buy Blog Forum Support

[BUG?] Changing view.sel() in a WindowCommand

[BUG?] Changing view.sel() in a WindowCommand

Postby bizoo on Thu Oct 25, 2012 8:18 am

When you change view.sel() in a sublime_plugin.WindowCommand, the selection is not visually updated until you do something else in the view (move cursor, scroll, change view, ...)
If you put your caret somewhere in a file and run this command using a keybindings:
Code: Select all
class ExampleCommand(sublime_plugin.WindowCommand):
    def run(self):
        self.window.active_view().sel().clear()
        self.window.active_view().sel().add(0)

the caret stay where it was until you try to move it, then it jump to the first char.
IMO it's a bug.
bizoo
 
Posts: 870
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: [BUG?] Changing view.sel() in a WindowCommand

Postby bizoo on Thu Oct 25, 2012 9:35 am

I resolved this issue using a begin/end_edit:
Code: Select all
class ExampleCommand(sublime_plugin.WindowCommand):
    def run(self):
        edit = self.window.active_view().begin_edit()
        self.window.active_view().sel().clear()
        self.window.active_view().sel().add(0)
        self.window.active_view().end_edit(edit)

Now it works fine.
I think that it make sense to create an edit if you change something to the view, including the selections.
I suppose that this is the way ST2 know if a view need to be refreshed.

But I like to have a confirmation that this is the way it must work, and that is not a bug. (Jon?)
bizoo
 
Posts: 870
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot] and 37 guests