Open colinta opened 5 years ago
Thanks for this fix
. What I ended up doing is using the following bits:
class ElmRescrollCommand(sublime_plugin.TextCommand):
def run(self, edit, prev_pos, t):
if t > 0:
if prev_pos == list(self.view.viewport_position()) :
sublime.set_timeout(lambda: self.run(edit, prev_pos, t-10), 10)
else:
self.view.set_viewport_position(prev_pos, False)
and
output, errors = p.communicate()
rescroll = lambda: self.view.run_command('elm_rescroll', { "prev_pos": self.view.viewport_position(), "t": 700 })
sublime.set_timeout(rescroll, 10)
This still creates a blink on my computer but it better than the original solution in this patch.
Addresses #65. After running the 'elm-format' command, a timeout function scrolls to the previous viewport location, nothing more than that! I played with the timeout value until it consistently restored the scroll position.
Improvements: The viewport doesn't always scroll to the top, so a check of
viewport_position
would help, but in my testing if the viewport didn't scroll this plugin didn't really have much effect.I didn't see any "on scroll" event on
EventListener
orViewEventListener
, but another improvement would be a series of short timeouts, ~100ms, until a max timeout is reached (700-1000ms), and each timeout would check the position. That would restore the position as quickly as possible. But "perfect" is the enemy of "done" and I wanted to be done. 😉