Sublime Forum

Weird scrolling with insert command

#1

The most basic reproduce I found is the following:

v = window.new_file(); v.run_command("insert", {"characters": "text\n" * 10})

Expected behavior: Text is inserted and not scrolled
Actual behavior: Inserted AND scrolled to the last line

This must be run in one line, splitting the two expressions into two console commands works as expected.

However, it gets weirder. If you run the following command repetitively, you can observe different results:

import sublime
import sublime_plugin


_view = None

def get_view(window):
    global _view

    if not _view or not _view.window():
        _view = window.new_file()
        _view.set_scratch(True)
        _view.settings().set("auto_indent", False)

    return _view


class TestCommandCommand(sublime_plugin.WindowCommand):
    def run(self):
        get_view(self.window).run_command('insert', {'characters': "test\n" * 10})

On the first run the same as above happens. However, on the second run the text is also scrolled down to the last line. Any following call (assuming the view still exists) will then scroll only when the text would exceed the view, which is the expected behavior.

Here is a recording with how it looks like when run 6 times consecutively:

Tests were confirmd on a fresh ST3 portable version on 3073 and Windows7.

0 Likes

#2

There is more.

If you use view.show like follows it works pretty much as expected:

import sublime
import sublime_plugin


_view = None

def get_view(window):
    global _view

    if not _view or not _view.window():
        _view = window.new_file()
        _view.set_scratch(True)
        _view.settings().set("auto_indent", False)

    return _view


class TestCommandCommand(sublime_plugin.WindowCommand):
    def run(self):
        view = get_view(self.window)
        previous_size = view.size()
        view.run_command('insert', {'characters': "test\n" * 10})

        view.show(previous_size)

However, if you insert text before retrieving view.size() things get weird again and the view.show call seems to be ignored.

import sublime
import sublime_plugin


_view = None

def get_view(window):
    global _view

    if not _view or not _view.window():
        _view = window.new_file()
        _view.set_scratch(True)
        _view.settings().set("auto_indent", False)

    return _view


class TestCommandCommand(sublime_plugin.WindowCommand):
    def run(self):
        view = get_view(self.window)
        view.run_command('insert', {'characters': "ayyy\n" * 3})
        previous_size = view.size()
        view.run_command('insert', {'characters': "test\n" * 10})

        view.show(previous_size)
        print("showing", previous_size)

0 Likes

#3

Thanks for the repro, this should be fixed in the next build

0 Likes

#4

Despite not mentioned in the changelog I can confirm this is fixed.

0 Likes