Sublime Forum

Visible region

#1

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.

0 Likes

#2

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

0 Likes

#3

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.

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.

0 Likes

#4

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

0 Likes

#5

Very nice… I love the scope filtering option.

Other scopes such as “variable” or “function” might be useful for refactoring too.

0 Likes

#6

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.

0 Likes