Compare commits
2 Commits
507a7e5d92
...
70022a9b6c
| Author | SHA1 | Date | |
|---|---|---|---|
| 70022a9b6c | |||
| 1f7b68e432 |
@ -129,6 +129,28 @@ class OpenMarkdownPreviewCommand(sublime_plugin.TextCommand):
|
|||||||
infos_to_log = markdown_view.settings().get(MARKDOWN_VIEW_INFOS)
|
infos_to_log = markdown_view.settings().get(MARKDOWN_VIEW_INFOS)
|
||||||
print("--- MarkdownLivePreview: Stored infos on markdown_view {}: {} ---".format(markdown_view.id(), infos_to_log))
|
print("--- MarkdownLivePreview: Stored infos on markdown_view {}: {} ---".format(markdown_view.id(), infos_to_log))
|
||||||
|
|
||||||
|
# Manually trigger the initial setup and render via the listener
|
||||||
|
# Use set_timeout_async to run it after the command finishes
|
||||||
|
print("--- MarkdownLivePreview: Scheduling setup_and_update_preview for md_view: {}, pv_view: {} ---".format(markdown_view.id(), preview_view.id()))
|
||||||
|
sublime.set_timeout_async(lambda: self.trigger_listener_setup(markdown_view.id(), preview_view.id()), 0)
|
||||||
|
|
||||||
|
# Helper method to find and call the listener instance method
|
||||||
|
# This is needed because the listener isn't easily accessible directly from the command instance
|
||||||
|
def trigger_listener_setup(self, md_view_id, pv_view_id):
|
||||||
|
print("--- MarkdownLivePreview: trigger_listener_setup running for md_view: {}, pv_view: {} ---".format(md_view_id, pv_view_id))
|
||||||
|
# Find the listener instance (this is a bit indirect, but common in ST plugins)
|
||||||
|
listener_instance = None
|
||||||
|
for listener in sublime_plugin.event_listeners:
|
||||||
|
if isinstance(listener, MarkdownLivePreviewListener):
|
||||||
|
listener_instance = listener
|
||||||
|
break
|
||||||
|
|
||||||
|
if listener_instance:
|
||||||
|
print("--- MarkdownLivePreview: Found listener instance, calling setup_and_update_preview ---")
|
||||||
|
listener_instance.setup_and_update_preview(md_view_id, pv_view_id)
|
||||||
|
else:
|
||||||
|
print("--- MarkdownLivePreview: ERROR: Could not find MarkdownLivePreviewListener instance to trigger setup! ---")
|
||||||
|
|
||||||
def is_enabled(self):
|
def is_enabled(self):
|
||||||
# FIXME: is this the best way there is to check if the current syntax is markdown?
|
# FIXME: is this the best way there is to check if the current syntax is markdown?
|
||||||
# should we only support default markdown?
|
# should we only support default markdown?
|
||||||
@ -184,8 +206,9 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener):
|
|||||||
return # Preview view was closed before loading finished
|
return # Preview view was closed before loading finished
|
||||||
|
|
||||||
print("--- MarkdownLivePreview: on_load_async found valid preview_view {} ---".format(preview_view.id()))
|
print("--- MarkdownLivePreview: on_load_async found valid preview_view {} ---".format(preview_view.id()))
|
||||||
self.phantom_sets[markdown_view.id()] = sublime.PhantomSet(preview_view)
|
# PhantomSet creation is now handled by setup_and_update_preview triggered from the command
|
||||||
print("--- MarkdownLivePreview: PhantomSet created for preview_view {} ---".format(preview_view.id()))
|
# self.phantom_sets[markdown_view.id()] = sublime.PhantomSet(preview_view)
|
||||||
|
# print("--- MarkdownLivePreview: PhantomSet created in on_load_async for preview_view {} ---".format(preview_view.id())) # Keep log commented
|
||||||
self._update_preview(markdown_view)
|
self._update_preview(markdown_view)
|
||||||
|
|
||||||
def on_close(self, markdown_view):
|
def on_close(self, markdown_view):
|
||||||
@ -321,6 +344,31 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener):
|
|||||||
)
|
)
|
||||||
print("--- MarkdownLivePreview: Updated phantoms in preview_view {} ---".format(preview_view.id()))
|
print("--- MarkdownLivePreview: Updated phantoms in preview_view {} ---".format(preview_view.id()))
|
||||||
|
|
||||||
|
def setup_and_update_preview(self, markdown_view_id, preview_view_id):
|
||||||
|
print("--- MarkdownLivePreview: setup_and_update_preview called for md_view: {}, pv_view: {} ---".format(markdown_view_id, preview_view_id))
|
||||||
|
markdown_view = sublime.View(markdown_view_id)
|
||||||
|
preview_view = sublime.View(preview_view_id)
|
||||||
|
|
||||||
|
if not markdown_view.is_valid():
|
||||||
|
print("--- MarkdownLivePreview: ERROR in setup_and_update: markdown_view {} is not valid ---".format(markdown_view_id))
|
||||||
|
return
|
||||||
|
if not preview_view.is_valid():
|
||||||
|
print("--- MarkdownLivePreview: ERROR in setup_and_update: preview_view {} is not valid ---".format(preview_view_id))
|
||||||
|
return
|
||||||
|
|
||||||
|
# Create PhantomSet if it doesn't exist (shouldn't at this point)
|
||||||
|
if markdown_view_id not in self.phantom_sets:
|
||||||
|
print("--- MarkdownLivePreview: Creating PhantomSet for preview_view {} in setup ---".format(preview_view.id()))
|
||||||
|
self.phantom_sets[markdown_view_id] = sublime.PhantomSet(preview_view)
|
||||||
|
else:
|
||||||
|
# This case might occur if the command is run multiple times rapidly? Ensure it's associated correctly.
|
||||||
|
print("--- MarkdownLivePreview: Warning: PhantomSet already existed for markdown_view {} in setup. Re-associating with preview_view {}. ---".format(markdown_view_id, preview_view.id()))
|
||||||
|
self.phantom_sets[markdown_view_id].view = preview_view # Ensure it points to the correct view
|
||||||
|
|
||||||
|
# Trigger the first update
|
||||||
|
print("--- MarkdownLivePreview: Triggering initial _update_preview from setup ---")
|
||||||
|
self._update_preview(markdown_view)
|
||||||
|
|
||||||
|
|
||||||
def get_settings():
|
def get_settings():
|
||||||
return sublime.load_settings("MarkdownLivePreview.sublime-settings")
|
return sublime.load_settings("MarkdownLivePreview.sublime-settings")
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user