Home Download Buy Blog Forum Support

subtracting folded regions from visible_region

subtracting folded regions from visible_region

Postby tednaleid on Mon Dec 31, 2012 9:28 pm

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
Code: Select all
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
Code: Select all
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.
tednaleid
 
Posts: 7
Joined: Sat Dec 22, 2012 3:41 am

Re: subtracting folded regions from visible_region

Postby adzenith on Wed Jan 02, 2013 7:48 pm

I was about to paste a link to Volcanoes but I see you're already following it. :)
adzenith
 
Posts: 1217
Joined: Mon Oct 19, 2009 9:12 pm

Re: subtracting folded regions from visible_region

Postby tednaleid on Thu Jan 03, 2013 1:01 am

adzenith wrote:I was about to paste a link to Volcanoes but I see you're already following it. :)


Yep :). 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.
tednaleid
 
Posts: 7
Joined: Sat Dec 22, 2012 3:41 am

Re: subtracting folded regions from visible_region

Postby highend on Thu Jan 03, 2013 1:05 am

@tednaleid

Finally a replacement for easymotion for vim? :)

I've raised two issues (one is a feature request) on your github repository.
highend
 
Posts: 94
Joined: Fri Jan 20, 2012 2:47 pm

Re: subtracting folded regions from visible_region

Postby FichteFoll on Sat Jan 19, 2013 5:31 pm

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.
FichteFoll
 
Posts: 405
Joined: Fri Mar 16, 2012 11:49 pm
Location: Germany

Re: subtracting folded regions from visible_region

Postby tednaleid on Sat Jan 19, 2013 6:36 pm

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.
tednaleid
 
Posts: 7
Joined: Sat Dec 22, 2012 3:41 am

Re: subtracting folded regions from visible_region

Postby tednaleid on Sun Jan 20, 2013 1:35 am

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!
tednaleid
 
Posts: 7
Joined: Sat Dec 22, 2012 3:41 am


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 15 guests