open view in current window not in new one

This commit is contained in:
2025-04-25 09:51:10 +02:00
parent e6a880d2a4
commit 34f8b3d733

View File

@ -72,19 +72,24 @@ class OpenMarkdownPreviewCommand(sublime_plugin.TextCommand):
syntax_file = original_view.settings().get("syntax") syntax_file = original_view.settings().get("syntax")
if file_name: # don't close the original view; keep it in your main window:
original_view.close() # if file_name:
else: # original_view.close()
# the file isn't saved, we need to restore the content manually # else:
# # the file isn't saved, we need to restore the content manually
# total_region = sublime.Region(0, original_view.size())
# content = original_view.substr(total_region)
# original_view.erase(edit, total_region)
# original_view.close()
# # FIXME: save the document to a temporary file, so that if we crash,
# # the user doesn't lose what he wrote
if not file_name:
# If the file isn't saved, we still need the content for the new view
total_region = sublime.Region(0, original_view.size()) total_region = sublime.Region(0, original_view.size())
content = original_view.substr(total_region) content = original_view.substr(total_region)
original_view.erase(edit, total_region)
original_view.close()
# FIXME: save the document to a temporary file, so that if we crash,
# the user doesn't lose what he wrote
sublime.run_command("new_window") # instead of making a new window, grab your existing one:
preview_window = sublime.active_window() preview_window = original_view.window()
preview_window.run_command( preview_window.run_command(
"set_layout", "set_layout",
@ -172,7 +177,8 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener):
if markdown_view.id() in self.phantom_sets: if markdown_view.id() in self.phantom_sets:
del self.phantom_sets[markdown_view.id()] del self.phantom_sets[markdown_view.id()]
self.preview_window.run_command("close_window") # dont close the entire window—just let the user close the preview tab:
# self.preview_window.run_command("close_window")
# find the window with the right id # find the window with the right id
original_window = next( original_window = next(