elm-format-on-save icon indicating copy to clipboard operation
elm-format-on-save copied to clipboard

Viewport position changes on format

Open dpinn opened this issue 4 years ago • 0 comments

Whenever I save the file, and thereby actuate elm-format-on-save, the window scrolls all the way to the right, hiding most of the code.

Could be related to https://github.com/jonlabelle/SublimeJsPrettier/pull/171.

The format class from elm_format.py would look something like this:

class ElmFormatCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        elm_format = find_elm_format(self.view)

        if elm_format == None:
            return

        region = sublime.Region(0, self.view.size())
        content = self.view.substr(region)
        previous_position = self.view.viewport_position()

        stdout, stderr = subprocess.Popen(
            [elm_format, '--stdin', '--yes', '--elm-version=0.19'],
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            shell=os.name=="nt").communicate(input=bytes(content, 'UTF-8'))

        if stderr.strip():
            open_panel(self.view, re.sub('\x1b\[\d{1,2}m', '', stderr.strip().decode()))
        else:
            self.view.replace(edit, region, stdout.decode('UTF-8'))
            self.view.set_viewport_position((0, 0), False)
            self.view.set_viewport_position(previous_position, False)
            self.view.window().run_command("hide_panel", {"panel": "output.elm_format"})

dpinn avatar Aug 16 '21 10:08 dpinn