Hi all,
I’m a 53 year old newbie - waited as long as I could to post here, but I’m stumped.
I am writing a simple plugin to handle wiki-like link references in Markdown so that I can cross reference between headers in my work notes. I have three different styles per Markdown convention:
[header] - header within the same file
Some text - header within the same file with alternate link name
Some text header within some other file (type 3 below)
First two work fine - I take the header text “slugify” per method provided in Markdown packages, find the matched location and center the view on the header. The last one works fine if the file is already in a view - view switches to the other file, then centers on the header.
The problem I have is if the other file is not already open: it looks like the search for headers is executing before the file is loaded, so no headers are found.
It looks to me like I need to use the on_load event listener to wait until the file is fully loaded into the view before searching for headers, but I can’t figure out how this is done.
Here is the relevant portion of my code:
# Form path to file and open if type 3
if lType == 3:
path = text[int(lPath)+1:int(rPath)]
activeView = self.view.window().open_file(path)
activeView.window().focus_view(activeView)
else:
activeView = self.view.window().active_view()
print(activeView.file_name())
print(activeView.is_loading()) #Always returns TRUE if file wasn't already in a view
## Need to wait under new file is loaded, something
## to do with EventListener.on_load()?
# find all the headers, slugify, and stop on a match
locations = activeView.find_all('^\#]+')
while len(locations):
location = locations.pop(0)
slug = slugify(activeView.substr(activeView.line(location.end())),'-')
print(slug)
if slug == link:
print('match!')
activeView.show_at_center(location)
break
Any help would be appreciated.
- Kurt