Sublime Forum

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

#1

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:

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.

0 Likes

#2

I resolved this issue using a begin/end_edit:

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

0 Likes