Sublime Forum

Please fixme: A reproducible bug in set_viewport_position

#1

Hi,

I found a way to reproduce a bug found in “set_viewport_position”

1 - With default sublime installation and no plugins. Even with all the default py files uninstalled (this makes no difference).
2 - Save this script as file set_viewport_position_bug.py

import sublime, sublime_plugin class setviewport_bug(sublime_plugin.EventListener): def on_load(self, view): view.set_viewport_position((0, 500), False) print view.viewport_position()

This will set the vertical position to 500 on every file you open.

3 - Now open a big file via “main menu bar” -> “file” -> “open file”
I selected for convenience the file “Packages/Color Scheme - Default/Monokai.tmTheme” (please select the same file.)
You will see that the view port is scrolled correctly to 500.
You can check this from the console with :

>>> sublime.active_window().active_view().viewport_position() (0.0, 500.0)
4 - Now, here is the bug.
Open the same file via the sidebar. And you will notice that the view is not scrolled.

>>> sublime.active_window().active_view().viewport_position() (0.0, 20.0)

It stay on (0.0, 20.0). I’m not sure the reason on this, but it seems that there is something in the sidebar that is setting this value to 20.
This same thing happens when using “CTRL+P”, so I guess this has somthing to do with the code of the “preview”

Can you please do a quick check if there is something there overwriting this value. Because most of the time is unusable and this api is very handy.

I would recommend to use the file “Packages/Color Scheme - Default/Monokai.tmTheme” because the problem is reproducible 100%

Thanks.

0 Likes

API Requests
#2

This is very strange because is only happening with some file types.

For example if I rename Monokai.tmTheme to Monokai.css this is not reproducible.

This seems to be reproducible with xml, txt, html and I don’t know if more files.

0 Likes

#3

I just updated the example:

import sublime, sublime_plugin class setviewport_bug(sublime_plugin.EventListener): def on_load(self, view): view.set_viewport_position((0, 500), False) print (view.viewport_position())
Save this a bug.py

  • Open a big file, with more than 30 lines
  • The first time it opens is stay at line 1.
  • The next time you open this file will scroll correctly.

Problems:
Now not only the view is not scrolled, the following API call is lying.

print (view.viewport_position())

is printing (0.0, 500.0)
But that is not correct because the first visible line is 1. And also this is confirmed by

 sublime.active_window().active_view().viewport_position()

Which display (0.0, 0.0)

It looks like sublime text, overwrite the scroll the first time the file is opened.
The problem is always reproducible when you open a file from -> File -> Open Recent -> Pick the file.

Please fix! :unamused:

0 Likes

#4

bump

0 Likes

#5

Please fix this. BufferScroll relies on it and it is an invaluable plugin.
Thanks.

0 Likes

#6

^ Creating an account to just post this, deserves a fix :stuck_out_tongue:, unfortunately, not on my end.

0 Likes

#7

same problem.

if view.scope == text.*: sublime won’t restore.

only restore view.scope == source.*

1 Like