Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

colinta
Copy link

@colinta colinta commented Apr 11, 2019

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. 😉

@pdamoc
Copy link

pdamoc commented Jun 16, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants