Sublime Forum

Getting a drop down icon in a view

#1

ST3 has a little arrow besides the line number that hides a certain section of code from view. Is it possible via the ST3 API to implement a drop down in a view that hides a certain section of text below it ?

0 Likes

#2

You could use the gutter for that (see add_regions() and example of it in Packages/Default/mark.py).
Check this post to know how to detect click in the gutter.
Another way would be to use phantoms: where you would place an arrow directly in the text area.
To hide section of code check the fold/unfold functions.

2 Likes

#3

I believe by default Phantoms don’t allow their content to be editable. Is there a way to make the content editable ?

0 Likes

#4

No, they are read-only for the user, but why would you need it to be editable, if it is just supposed to be an arrow to fold/unfold text ?
If you mean changing the arrow icon when the user click it, then it is not a problem, since your plugin controls the phantom content and can change it.

1 Like

#5

You can not add icons to the gutter and an event handler for when that icon is clicked, so add_regions isn’t going to help you here aside from visualization. You can, add a hover popup to the gutter for the lines you have a region in and within the popup provide a link that the user can click to fold a custom region.

This is similar to phantoms, except phantoms are rendered inline and not on-hover.

1 Like

#6

The purpose of asking the original question was to assess whether I can create something like a ‘cheat sheet’ in a separate output view on a key stroke containing code snippets which I can hide or show based on the drop down.

0 Likes

#7

Yes, that’s totally possible using phantoms. https://packagecontrol.io/packages/Debugger, for example, does something like that.

1 Like