Cat Black
Cat Black

Reputation: 13

How do you change the viewport size of the sublimetext in Python?

I'm trying to create my first plugin for Sublime Text 3.

How do I set the viewport size? I usually divide the layout into two, what I want to do is change the viewport size for the focused layout, so that I can read more content in the focused layout.

I was able to get the size of the viewport with the viewport_extent() method of the view, but I don't know how to set it to a new size.

Upvotes: 1

Views: 973

Answers (1)

Keith Hall
Keith Hall

Reputation: 16065

Plugins do not have the ability to resize ST panels, or directly resize a viewport, but you can size the layout split when more than one row or column group is displayed.

You will want to use window.get_layout() to get the current layout together with window.set_layout to set the new layout, passing in the necessary arguments to give the active/focused group a larger size ratio.

A single pane layout looks like this in get_layout:

{'cells': [[0, 0, 1, 1]], 'rows': [0.0, 1.0], 'cols': [0.0, 1.0]}

An evenly split 2 column layout looks like this:

{'cells': [[0, 0, 1, 1], [1, 0, 2, 1]], 'rows': [0.0, 1.0], 'cols': [0.0, 0.5, 1.0]}

A wider left column might look like this:

{'cells': [[0, 0, 1, 1], [1, 0, 2, 1]], 'rows': [0.0, 1.0], 'cols': [0.0, 0.75, 1.0]}

you can determine which group is active using window.active_group(), and decide how to set the ratio based on that.


Note: some API functions don't appear in the official documentation. For exploration purposes, it can be useful to execute dir(window) or dir(view) in the ST console, to see what properties and methods are available.

Upvotes: 1

Related Questions