Sublime Forum

Dev Build 3070

#1

Dev Build 3070 is out now.

There are a few new API functions in 3070:

class View:
    def show_popup(self, content, flags = HTML, location = -1,
        max_width = 320, max_height = 240,
        on_navigate = None, on_hide = None):
        ...

    def update_popup(self, content):
        ...

    def is_popup_visible(self):
        ...

    def hide_popup(self):
        ...

This enables plugins to show a tooltip style window within a View. A simple usage example is:

view.show_popup('Hello, <b>World!</b><br><a href="moo">Click Me</a>', on_navigate=print)

The popup accepts a subset of HTML and CSS. Supported tags:

p, br, a, b, u, i, a, h1…h6, big, tt, div, style

Supported CSS properties:

display (block or inline only), background-color (block elements only), color, margin, font-size, font-family, font-weight, font-style, text-decoration. Supported units are px, pt and em.

CSS may be provided in tags and style= attributes, but external style sheets aren’t supported. Only simple selectors (i.e., comma separated lists of “p”, “.class”, and “#id” selectors) are supported.

By default the popup will be run with a user style sheet matching the font size and font family that the View is using, but this can be overridden via regular CSS.

The full HTML5 parsing algorithm isn’t used, so please be mindful to pass in only well formed HTML. Only a few entities are supported: < > & and  

When an tag is clicked on, the on_navigate callback, if any, will be called, but otherwise no further action is taken.

Edit: Nothing in the popup API is currently set in stone, and is very much liable to change in a future build. I’m more than happy to take feedback here.

Please note that if you are using the BracketHighlighter plugin, ensure you have updated to the latest version or it will be disabled, due to an incompatibility Sublime Text introduced in 3067.

3 Likes

Documentation for show_popup()
Click on/hover over region and show overlay text
Hover/click events in gutter?
#2

I’ll be downloading this first this tomorrow morning. Can’t wait to start adding pop-ups to show function parameters for our code base.

Amazing work, keep the updates coming!

0 Likes

#3

This looks like a nice release. It will be fun to play with the new tooltip API.

0 Likes

#4

Tooltip is incredibly useful. Nice to see ST on track again!
Quick question: How to define the size of tooltip window?

0 Likes

#5

max_width = 320, max_height = 240
Im guessing this is it.

0 Likes

#6

happy :smiley:

0 Likes

#7

Tooltip is incredibly useful; add hover style support for anchors will make it easier to click.

0 Likes

#8

Great, thanks jps for this very nice update.

Hope plugin developers will use the new popup API wisely and let user choose if and when to display it, having dozen plugins fighting for it is annoying (like gutter icons).

0 Likes

#9

Me like this update :wink: Thanks.

0 Likes

#10

[quote=“bizoo”]Great, thanks jps for this very nice update.

Hope plugin developers will use the new popup API wisely and let user choose if and when to display it, having dozen plugins fighting for it is annoying (like gutter icons).[/quote]

+1. Use wisely.

0 Likes

#11

Great update, can’t wait to start testing the popup :smile:

I found a bug with the goto definition with multiple location for a symbol: the file shown is the second in the list while the first one is selected. If change selection then i get the correct file (I hope I’m clear :stuck_out_tongue: ). And if I press enter immediately, once again the correct file is open.

0 Likes

#12

There’s a (new I think but not sure) bug in the show_quick_panel() method:
If you type this in the console:

view.window().show_quick_panel(items = "0","1","2","3"], selected_index = 3, on_select = lambda x: print("s:%i"%x), on_highlight = lambda x: print("h:%i"%x))

the result before selecting anything is:

h:1

Whatever you put in the selected_index argument (even -1), the on_highlight callback is called with 1 when the panel open.
This cause an issue in the Goto symbol command.

In addition, when selecting an item, both on_highlight and on_select are called. Not sure it is correct.

edit: Clams was quicker :smiley:

0 Likes

#13

[quote]The popup accepts a subset of HTML and CSS. Supported tags:

p, br, a, b, u, i, a, h1…h6, big, tt, div, style[/quote]

I’d say you should also add span tag as well. It may be suitable for whatever doesn’t fit in the list (also, i think you should also add small tags to that list, because it seems that it works).

There is a way of customizing the background (or padding) of the popup? Or not yet?

0 Likes

#14

I wish img tag and list tags (ul,ol,li) where supported.

0 Likes

#15

Can you give axample of using CSS? I tries this but not work:self.view.show_popup('Hello, <b>World!</b><br><a href="moo">Click Me</a> <style>color=red</style>', on_navigate=print)

0 Likes

#16

^ THIS

0 Likes

#17

Know your css:

<style> b { color:red } </style>

0 Likes

#18

You can use regular CSS for this:

view.show_popup('<style>body { margin: 1px } html { background-color: green }</style>Hello')

Also, although not mentioned, the span tag will also work.

0 Likes

#19

Duh! I was trying a global selector: * { background:red } (instead of background-color).

I’d say you should also add background (just as a shorthand to background-color).

Also, i found a bug with tooltips: if a tooltip is visible and another window (non ST) shows over, things will go a bit south:

0 Likes

#20

Holy mother of…

Yes Jon! That’s it now, you can disappear again <3

0 Likes