Home Download Buy Blog Forum Support

Trigger find in all open files / project via Sublime command

Trigger find in all open files / project via Sublime command

Postby ericandrewlewis on Wed Sep 12, 2012 12:43 pm

I have a plugin I'm working on to trigger finding the current selection within all open files / project (Find in Files...).

Anyone know how I trigger this via a Sublime command? I've gotten as far as grabbing the selection, or if there is no selection the word the cursor is currently within.

Code: Select all
import sublime, sublime_plugin


class QuickSearchCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        for region in self.view.sel():
            line = self.view.word(region)
            if region.empty():
                # search with self.view.substr(line) here
            else:
                # search with self.view.substr(region) here

ericandrewlewis
 
Posts: 4
Joined: Mon Sep 10, 2012 4:09 pm

Re: Trigger find in all open files / project via Sublime command

Postby adzenith on Thu Sep 13, 2012 6:30 pm

You'll definitely be able to open the find in files panel, but I don't know if you'll actually be able to initiate a search from your plugin (maybe try sending the "return" key?). In any case I don't think you can find in files without going through the panel—the underlying functionality isn't available through the API.
adzenith
 
Posts: 1204
Joined: Mon Oct 19, 2009 9:12 pm

Re: Trigger find in all open files / project via Sublime command

Postby lunixbochs on Fri Sep 14, 2012 7:29 pm

Run this after selecting your string. This should get you the "Find in files" panel open with your selected string handy.

Code: Select all
view.run_command('slurp_find_string')
window.run_command('show_panel', {'panel': 'find_in_files'})
lunixbochs
 
Posts: 91
Joined: Fri Oct 08, 2010 10:18 pm


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 3 guests