Home Download Buy Blog Forum Support

Visible region

Visible region

Postby gpfsmurf on Tue Mar 17, 2009 6:01 pm

Is there a way to get the currently visible region?

What I'm trying to do is to filter the current selection so that the selected text that is not currently visible to the user is discarded from the selection.
gpfsmurf
 
Posts: 211
Joined: Mon Jun 23, 2008 6:31 pm

Re: Visible region

Postby gpfsmurf on Wed Mar 18, 2009 5:19 pm

I extensively use Alt-F3 for quick search & replace.

However, it can sometimes select some unwanted text somewhere far away in the same file. I can usually see it in the minimap so it's not error-inducing but it means I need to select the region I want and perform a normal search/replace.

I figured using Shift-Alt-F3 to perform a quick find on the visible part of the file might be handy, although I must admit I won't know for sure until I actually try it
gpfsmurf
 
Posts: 211
Joined: Mon Jun 23, 2008 6:31 pm

Re: Visible region

Postby gpfsmurf on Thu Mar 19, 2009 5:20 pm

Search between bookmarks if there is only one selection? Set up search areas.

Sounds good but I don't see anything about bookmarks in the API documentation.
In the same line of thinking, the search could be done over the current syntax scope (ctrl-shift-space) or the current bracket scope (ctrl-shift-m), but those scopes are not always useful. A 'current function scope' would be nicer.

For the moment, maybe you could make a plugin where you ctrl mouse click the extents as 2 empty selections, then the search as a 3rd full selection.

Sounds like a fair alternative... I'll try that.
The two outer selections must be empty and will delimit the search area.
The middle selection will be used as a search pattern; if it's an empty selection, the whole word will be used.
gpfsmurf
 
Posts: 211
Joined: Mon Jun 23, 2008 6:31 pm

Re: Visible region

Postby gpfsmurf on Fri Mar 20, 2009 6:14 pm

Well here's what I did - I was proud of it until I saw your code.

It doesn't work with bookmarks, only with 3 selections. It's also very un-pythonic, now that I look at it.
http://pastie.org/422164

There is one problem with your solution though: the user's search string will be interpreted as a regex, so if it contains dots or special characters, it'll mess up the results. Using the flag "sublime.LITERAL" would probably fix it
gpfsmurf
 
Posts: 211
Joined: Mon Jun 23, 2008 6:31 pm

Re: Visible region

Postby gpfsmurf on Tue Mar 24, 2009 7:19 pm

Very nice... I love the scope filtering option.

Other scopes such as "variable" or "function" might be useful for refactoring too.
gpfsmurf
 
Posts: 211
Joined: Mon Jun 23, 2008 6:31 pm

Re: Visible region

Postby gpfsmurf on Tue Mar 31, 2009 4:25 pm

Works pretty well...

The only problem that I see is that the view.find() function doesn't actually change the user's search string. So if you press Alt-F3, and then you press F3, it will look for the user's last search string instead of the new one the plugin is using.

Obviously in many cases that's the behavior that we would want, but in this particular case, it's not. There should be an option in view.find() (or a different function) to specify if we want to change the search string.
gpfsmurf
 
Posts: 211
Joined: Mon Jun 23, 2008 6:31 pm


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 3 guests