Sublime Forum

Initializing search terms

#1

I have used show_panel to display the search panel using

	self.view.window().run_command("show_panel", {"panel":"find", "reverse":False})

Now I would like to specify the search string and the regular expression option. My search string is in a python variable and is not currently selected (so I can’t use the slurp_find_string command)

e.g for example to initialize the find/find in files from a library of named standard regular expressions.

0 Likes

#2

I found two ways to do almost what I wanted.

The first is to find the next instance of the search string myself and then select it via the API. Then it can be slurped to the find text string in the find panel.

         text = "dummy01"
          # Add word boundaries so that we only find complete words.
          reg = self.view.find("\\b" + text + "\\b", self.view.sel()[0].a, sublime.IGNORECASE )
          if reg:
             self.view.sel().add(reg)         # Add string to the selection (currently empty)
             self.view.show(reg)              # Make sure the result is visible
             self.view.window().run_command("show_panel",   {"panel": "find", "reverse": False})
             self.view.window().run_command("slurp_find_string")

This does exactly what I want for the first instance of the search string. But now I would like to find the next occurence using F3 and for that to work correctly I need to: set the whole word option and clear the case-sensitive option. I found commands for toggling these options but none to set them to a known value (or to get the current value so that I could conditionally toggle it)

The second way is to call up the “goto” panel and search for it as a symbol in the current file. This text is shown correctly (maybe with a list of alternatives) but I need an extra keypress to go to it and then have the same problems as above when I try to continue the search.

           view.window().run_command("show_overlay", {"overlay": "goto", "text": "#" + text });   #st3

Any ideas?

0 Likes

#3


0 Likes

Find in files from sublime API
#4

I’ve logged this on the Core issues repo as a feature request:

1 Like