I need a simple feature in my new plugin which is : open a specified file and than find the first occurrence of a give text.
eg:
Open a file named “xxx.txt” and then search for text “this is a good app” and scroll the opened view to the matched line.
And here is what I have tried:
class OpenAndFindCommand(sublime_plugin.WindowCommand):
def run(self):
self.window.open_file("D:\somefile.txt")
sublime.active_window().run_command("find_next", {"content":"text_to_find"})
def is_enabled(self):
return True
Unfortunately it did not work. The file is opened correctly but the cursor is not moved to the match line of the given text.
Then I tried it in another way : I opened the file “D:\somefile.txt” manually and then commented out the line:
#self.window.open_file("D:\somefile.txt")
and this time it works fine.
Any suggestion will be appreciated, thanks