Home Download Buy Blog Forum Support

Option "find_selected_text" doesn't work in incremental find

Option "find_selected_text" doesn't work in incremental find

Postby Netheril on Thu Feb 21, 2013 10:35 am

Dear all,

I'm a new Sublime Text user switching from Emacs. I prefer using incremental find because it is closer to the search behavior I'm familiar with. However, I found that, when using incremental find, current selected text doesn't appear in find box although option "find_selected_text" set to true. On the other hand, normal find works as expected at the same time.
I've searched this forum but only find one marginally related topic with no answer. So I would like to ask here. Is this a intended behavior or a bug? Is it possible to turn on "find_selected_text" feature for incremental find?
Thanks.
Netheril
 
Posts: 3
Joined: Thu Feb 21, 2013 10:04 am

Re: Option "find_selected_text" doesn't work in incremental find

Postby Netheril on Tue Feb 26, 2013 1:17 pm

Any comments? :)
Netheril
 
Posts: 3
Joined: Thu Feb 21, 2013 10:04 am

Re: Option "find_selected_text" doesn't work in incremental find

Postby jps on Tue Feb 26, 2013 10:50 pm

This is the intended behaviour
jps
Site Admin
 
Posts: 3077
Joined: Wed Mar 19, 2008 12:33 pm

Re: Option "find_selected_text" doesn't work in incremental find

Postby Netheril on Wed Feb 27, 2013 6:28 am

Thanks jps. Do you know the reason behind this decision? Is it possible to change this behavior by a plug-in? I may be able to do something here if this is the case.
Netheril
 
Posts: 3
Joined: Thu Feb 21, 2013 10:04 am

Re: Option "find_selected_text" doesn't work in incremental find

Postby jps on Wed Feb 27, 2013 7:07 am

It's not customisable, but you can use the regular find panel instead
jps
Site Admin
 
Posts: 3077
Joined: Wed Mar 19, 2008 12:33 pm

Re: Option "find_selected_text" doesn't work in incremental find

Postby robertcollier4 on Wed Feb 27, 2013 7:14 am

You can write whatever specific functionality you want via a plug-in. I was just tinkering around with this so here are the commands fresh from my memory.

To get you started:
Code: Select all
import sublime, sublime_plugin

class ExampleCommand(sublime_plugin.TextCommand):
   def run(self, edit):


This will get you the current selection:
Code: Select all
SearchTerm = self.view.substr(self.view.sel()[0])


This will let you find all matches for that text:
Code: Select all
RegionsResult = self.view.find_all(SearchTerm, sublime.IGNORECASE)


This will clear the old selection:
Code: Select all
self.view.sel().clear()


This will select the second occurance of SearchTerm in the document
Code: Select all
self.view.sel().add(sublime.Region(RegionsResult[1].a, RegionsResult[1].b))


If you want your own input panel, you can use:
Code: Select all
self.view.window().show_input_panel("Please enter custom incremental search text:", "", self.on_done, None, None)

def on_done(self, text):
   RegionsResultFromInputPanel = self.view.find_all(text, sublime.IGNORECASE)



These commands (taken from the menu) may also help you:
{ "command": "find_under", "caption": "Quick Find" },
{ "command": "find_all_under", "caption": "Quick Find All" },
{ "command": "find_under_expand", "caption": "Quick Add Next" },
{ "command": "slurp_find_string", "caption": "Use Selection for Find" },
robertcollier4
 
Posts: 154
Joined: Sun Feb 24, 2013 5:37 pm


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot] and 24 guests