Sublime Forum

Subtracting folded regions from visible_region

#1

I’m working on a plugin called SublimeJump (https://github.com/tednaleid/SublimeJump) that lets the user jump to any visible character in the view with a couple of keystrokes. It’s very similar to EasyMotion (vim) or AceJump (emacs/intellij) if you’re familiar with those.

I’ve got most of the functionality working but I’m stumped on how to get it to respect folded areas of code. Currently it lets you jump to folded areas which it should not do.

The documented API gives us View.visible_region() which returns a Region with the starting and ending characters on the view. As it’s a range, it doesn’t remove those areas of code that are folded.

The documented API doesn’t give any way to query for the folded areas that I can see. Unless there is a key that I can use to retrieve them from View.get_regions(key)?

If there is a way for me to get the folded regions in the visible_region, I could easily create a list of Regions out of them that really only decorates the truly visible text with jump targets.

0 Likes

#2

I was about to paste a link to Volcanoes but I see you’re already following it. :smile:

0 Likes

#3

Yep :smile:. I gave it a try and it’s a cool plugin but it wasn’t quite what I was looking for. It didn’t let me go to the exact character (which is sometimes not part of a word, like a bracket), just the start of a word. There were also some cases where I couldn’t go to the word I wanted to because all of it’s digraphs were used by other words.

0 Likes

#4

@tednaleid

Finally a replacement for easymotion for vim? :smile:

I’ve raised two issues (one is a feature request) on your github repository.

0 Likes

#5

The view.unfold() method returns the unfolded regions, you just need to re-fold them afterwards.

I found this in the “Default/fold.py” plugin which implements the basic folding commands and it is also stated in the API docs.

0 Likes

#6

Thanks FichteFoll, that could work to use View.unfold() to get the regions and then refold. I wonder if the screen would jump around though and that could be confusing for the user…

It’d be much better if there was a method in the API to just return the current folded regions. I’m sure that internally that ST2 has this information and hopefully exposing it in the UI wouldn’t be that tough.

I’ll play around with it to see if it’s confusing or workable with unfolding to get the regions and then refolding right away, that seems like the only way to do it with the current API.

0 Likes

#7

This ended up working well, and I don’t see any flickering or actual expansion of the folded regions (at least on OSX, haven’t tried other platforms). Support for this has been added into the plugin (https://github.com/tednaleid/sublime-EasyMotion/issues/1), thanks for the suggestion!

0 Likes