After some testing I’ve found the issue is only present when using WindowCommand (probably ApplicationCommand too), TextCommand works flawlessly.
So the viewport is updated after a TextCommand exit, but not after an ApplicationCommand.
Make some sense because as you don’t have an edit token, you can’t modify the buffer.
But view.sel() (and view.add_regions()) is somewhat special because it doesn’t actually modify the buffer and can be used outside an edit token.
So please @jps or @wbond, is it wrong to change view.sel() in a WindowsCommand or is it a bug in ST ?
This is my test code:
import sublime, sublime_plugin
class NotworkingCommand(sublime_plugin.WindowCommand):
toggle = True
def run(self):
self.toggle = not self.toggle
self.view = self.window.active_view()
if self.toggle:
region = sublime.Region(100, 105)
else:
region = sublime.Region(130, 135)
self.view.sel().clear()
self.view.sel().add(region)
self.view.show_at_center(region)
class WorkingCommand(sublime_plugin.TextCommand):
toggle = True
def run(self, edit):
self.toggle = not self.toggle
if self.toggle:
region = sublime.Region(100, 105)
else:
region = sublime.Region(130, 135)
self.view.sel().clear()
self.view.sel().add(region)
self.view.show_at_center(region)