Sublime Forum

How to launch the 'find' panel in clean state

#1

I’d like the ‘Find’ panel to launch with a clean slate every time I launch it. I’ve been trying to write a TextCommand for this but have been failing. Here’s what I have so far:

class LaunchEmptyFindPanelCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        self.view.window().run_command("show_panel", {"panel": "find"})
        panel_view = self.view.find_output_panel("find")
        panel_view.run_command("delete_word", {"forward": False, "sub_words": False})

I think the problem is with the line

panel_view = self.view.find_output_panel("find")

that is not retrieving the view object of the find panel. (How do I check/debug this by the way? I haven’t found a way to write to the console.) So I think my question is really: how do I get my hands on the panel’s view object?

Also, the delete_word command is just a hack that will only work when the previous search involved only one word. I would be happy to know the correct way of wiping the contents of the Find panel.

0 Likes

#2

when you show the find panel, you could run the select_all command to select the entire search pattern, then left_delete to delete it. I think executing those commands on window.active_view() after the find panel is shown should work, but I could be wrong.

the text box for the find pattern is not an output panel, so trying to get a view that way won’t work.

0 Likes

#3

Thank you.

It didn’t work, unfortunately. For example, this results in a left_delete occurring in the main window as opposed to the find panel:

class LaunchEmptyFindPanelCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        self.view.window().run_command("show_panel", {"panel": "find"})
        self.view.window().active_view().run_command("left_delete")

More ominously, even this doesn’t work (though it still deletes a character in the main window):

class LaunchEmptyFindPanelCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        self.view.window().run_command("show_panel", {"panel": "find"})
        all_views = self.view.window().views()
        for v in all_views:
            v.run_command("left_delete")

So it seems that the panel isn’t even a “view” of self.window().

0 Likes

#4

Yes, indeed, widget views (basically everything that shows up at the bottom or in a popup) are not normal views and cannot be found in window.views().

I don’t thing there is a proper way to always open the Find panel empty.

0 Likes

#5

have you checked to see what the effect of the slurp_find_string WindowCommand is with no selection?

0 Likes

#6

Yes this works, but only if the selection is nonempty, alas, which defeats the purpose…

In the meanwhile, I think I’ve figured out that what I really want (though having a clean find panel would be great) is for the find panel to close automatically whenever it loses focus. I’ll post this in another thread, though.

0 Likes

#7

Maybe you’d want the incremental find panel? It opens with ctrl+I and closes once you press enter (or escape, which will bring you back to your starting point).

0 Likes