From 34f8b3d733a81e40d10fa5f3915a6dca7db116e5 Mon Sep 17 00:00:00 2001 From: Christian Morpurgo Date: Fri, 25 Apr 2025 09:51:10 +0200 Subject: [PATCH] open view in current window not in new one --- MarkdownLivePreview.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/MarkdownLivePreview.py b/MarkdownLivePreview.py index c535d08..da25006 100644 --- a/MarkdownLivePreview.py +++ b/MarkdownLivePreview.py @@ -72,19 +72,24 @@ class OpenMarkdownPreviewCommand(sublime_plugin.TextCommand): syntax_file = original_view.settings().get("syntax") - if file_name: - original_view.close() - else: - # the file isn't saved, we need to restore the content manually + # don't close the original view; keep it in your main window: + # if file_name: + # original_view.close() + # 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()) 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") - preview_window = sublime.active_window() + # instead of making a new window, grab your existing one: + preview_window = original_view.window() preview_window.run_command( "set_layout", @@ -172,7 +177,8 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener): if markdown_view.id() in self.phantom_sets: del self.phantom_sets[markdown_view.id()] - self.preview_window.run_command("close_window") + # don’t 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 original_window = next(