Sublime Forum

Invalid viewport position when opening multiple files


I have this weird behavior when I open multiple files (say 5) at a certain line. For the last opened file (the one which has focus) the viewport position is fine, but when I switch to the other 4 tabs/views the viewport appears messed up all at the bottom (see screenshot). I wrote a script to reproduce this behavior, which occurs also in --safe-mode . The problem only occurs if I use ENCODED_POSITION flag to specify a file line. Without ENCODED_POSITION there’s no problem. I can solve this problem by running view.run_command("show_at_center") on on_activated event, but it’s a hacky solution.

Any idea on how to open multiple files at a given line with the correct viewport position?

import sublime
import tempfile

import sublime_plugin

text = """
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus quam tellus,
condimentum vel nulla ut, tempor rhoncus enim. Vestibulum ante ipsum primis in
faucibus orci luctus et ultrices posuere cubilia curae; Vestibulum vel est eget
dolor mollis luctus. In et elit egestas, suscipit justo vitae, accumsan lorem.
Donec lorem lacus, ullamcorper et mollis sed, aliquam vel enim. Morbi nec ex
sed sem scelerisque porta. Pellentesque vel urna ornare, pellentesque sem nec,
hendrerit purus. Proin auctor non elit ac scelerisque. Pellentesque non tellus
ullamcorper, luctus enim et, euismod elit. Quisque quis aliquam tortor, sed
ultrices nisl. Vestibulum lacinia sollicitudin mauris, non dapibus tortor
lobortis eget. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Morbi arcu nisi, bibendum imperdiet sollicitudin in, tincidunt et felis.

class HelloWorld(sublime_plugin.WindowCommand):
    def run(self):
        paths = []
        for x in range(5):
            with tempfile.NamedTemporaryFile("wt", delete=False) as f:

        lineno = 10
        for path in paths:
            path = f"{path}:{lineno}"
            view = self.window.open_file(path, flags=sublime.ENCODED_POSITION)