Sublime Forum

View.viewport_extent() returns (0.0, 0.0) in EventListener.on_load(view)

#1

My plugin displays images inline as phantoms. I’m trying to limit the image width to the viewport width.

My plugin processes files in an EventListener.on_load(view) handler. I’m reading view.viewport_extent() and view.layout_extent(), but both return wrong(?) values. They return correct values when I call these methods in EventListener.on_save(view).

on_load: file_name test.cpp, layout_extent: (48.3828125, 1015.0), viewport_extent: (0.0, 0.0)
on_save: file_name test.cpp, layout_extent: (713.0, 645.2), viewport_extent: (713.0, 508.8)

Do you have any suggestion when/from where I should call viewport_extent()?

It would be great if the documentation of
viewport_extent()
would mention when it is possible to call this method. Same for layout_extent().

0 Likes

#2

viewport_extent() seems to work when I call it from EventListener.on_load_async(view). But is it guaranteed to work?

layout_extent() doesn’t seem to work.

0 Likes

#3

You should generally use the _async functions anyway. To answer your question, you probably need to check whether view.is_loading - if it is False then some methods may not work as expected. I think the canonical solution is to poll it periodically using set_timeout calls.

1 Like

#4

Thank you, that works really well.

0 Likes