import functools, sublime, sublime_plugin
class open_file_with_custom_find_command(sublime_plugin.WindowCommand):
def run(self):
window = sublime.active_window()
window.run_command('hide_panel');
window.show_input_panel('Search For 1:', '', functools.partial(self.on_done1), None, None)
def on_done1(self, search_for1):
search_for1 = search_for1.strip()
if search_for1:
window = sublime.active_window()
window.run_command('hide_panel');
window.show_input_panel('Search For 2:', '', functools.partial(self.on_done2, search_for1), None, None)
def on_done2(self, search_for1, search_for2):
window = sublime.active_window()
view = window.active_view()
search_for2 = search_for2.strip()
if search_for1 and search_for2:
regions1 = view.find_all(search_for1, sublime.IGNORECASE)
regions2 = view.find_all(search_for2, sublime.IGNORECASE)
if regions1 and regions2:
for item1 in reversed(regions1):
sel_start = view.line(item1).end()
for item2 in reversed(regions2):
if item2.end() < sel_start:
substr = view.substr(sublime.Region(sel_start, item2.begin()))
print(substr)
if substr:
_view = window.new_file()
_view.run_command('insert', {'characters': substr})
break