Scrolling doesn't update selection

colinta 6 years ago • updated by Максим Зубков 4 years ago 2
This is also posted in the forums: http://www.sublimetext.com/forum/viewtopic.php?f=2&t=5471

The code is easy enough to test.  Open a new file.  Open the python console and type:

>>> edit = view.begin_edit('test')>>> view.insert(edit, 0, ("abcd"*12+"\n")*100)>>> view.end_edit(edit)>>> region = sublime.Region(4851, 4899)>>> view.sel().clear()>>> view.show_at_center(region)>>> view.sel().add(region)

At this point, the text should be highlighted, but it is not.  Compare with what happens when we add one more line:

>>> view.show_at_center(sublime.Region(4900, 4900))

Voilà, the selection is highlighted.

I noticed this happening when using plugins that highlight and scroll.  In my case, I'm using the SimpleMovements plugin to highlight multiple lines.  If my view doesn't scroll, the line is not highlighted, which looks like my plugin isn't working!

I've got a very hacky, temporary solution:
pos = self.view.viewport_position()self.view.show_at_center(sublime.Region(start, end))new_pos = self.view.viewport_position()if abs(new_pos[0] - pos[0]) <= 1.0 and abs(new_pos[1] - pos[1]) <= 1.0:    self.view.set_viewport_position((new_pos[0], new_pos[1] + 1))
This is still not fixed today :) Your workaround seem to not work for me either (view is not actually scrolled) so I did this instead: https://github.com/code-orchestra/colt-sublime-plugin/commit/9e6ffbf573fc60b356665ff2ba9ced614c71120f Spread the word!