def _move_viewport(self, command): """ Move the viewport to focus the region of a command. If the file of the command is not opened, then it will also open the file. """ self._remove_highlight() # open the file (change from transient to normal) # we must not await the loading, because it is already open # due to the on_change event file_name = command.file_name view = self.window.open_file(file_name) def move(): # at a caret to the section position and move the viewport # to the position view.sel().clear() view.sel().add(command.region) # view.show_at_center(command.start) view.show(command.start) # erase the regions self._remove_highlight(view) run_after_loading(view, move)
def _open_transient(self, command): """ Opens the file of a command in transient mode, focuses and highlights the region of the command """ file_name = command.file_name v = self.window.open_file(file_name, sublime.TRANSIENT) # add the highlight and focus the view after it has been loading run_after_loading(v, lambda: self._add_highlight(v, command.region)) run_after_loading(v, lambda: v.show(command.region))