SublimeElmLanguageSupport icon indicating copy to clipboard operation
SublimeElmLanguageSupport copied to clipboard

A hacky 'fix' for the scrolling bug - better'n'nothin'?

Open colinta opened this issue 6 years ago • 1 comments

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 or ViewEventListener, 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. 😉

colinta avatar Apr 11 '19 14:04 colinta

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.

pdamoc avatar Jun 16 '19 12:06 pdamoc