Remove entry in phantom_sets when markdown_view is closed

Otherwise the object would keep on growing forever. It probably would
never ever be a problem for anyone, but it just makes me feel better
This commit is contained in:
Mathieu PATUREL
2019-11-14 21:17:22 +11:00
parent cc28bfef96
commit 8c1012eb8c
4 changed files with 33 additions and 18 deletions

View File

@ -15,6 +15,7 @@ PREVIEW_VIEW_INFOS = "preview_view_infos"
# FIXME: put this as a setting for the user to choose?
DELAY = 500 # ms
# Terminology
# original_view: the view in the regular editor, without it's own window
# markdown_view: the markdown view, in the special window
# preview_view: the preview view, in the special window
@ -92,6 +93,8 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener):
# markdown_view.id(): phantom set
}
# FIXME: maybe we shouldn't restore the file in the original window...
def on_pre_close(self, markdown_view):
""" Close the view in the preview window, and store information for the on_close
listener (see doc there)
@ -118,6 +121,7 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener):
preview_view = markdown_view.window().active_view_in_group(1)
# FIXME: set the preview title
self.phantom_sets[markdown_view.id()] = sublime.PhantomSet(preview_view)
self._update_preview(markdown_view)
@ -131,6 +135,8 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener):
assert markdown_view.id() == self.markdown_view.id(), \
"pre_close view.id() != close view.id()"
del self.phantom_sets[markdown_view.id()]
self.preview_window.run_command('close_window')
# find the window with the right id
@ -150,11 +156,15 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener):
original_view.set_syntax_file(markdown_view.settings().get('syntax'))
# here, views are NOT treated independently, which is theoretically wrong
# but in practice, you can only edit one markdown file at a time, so it doesn't really
# matter.
# @min_time_between_call(.5)
def on_modified_async(self, markdown_view):
# FIXME: it keeps on flickering, it's really annoying
infos = markdown_view.settings().get(MARKDOWN_VIEW_INFOS)
if not infos:
return

16
live-testing/images.md Normal file
View File

@ -0,0 +1,16 @@
I'm not sure that it **actually** going to work, but it seems nicer than the [previous version][prev]
This is the first image from the local file system (absolute path, sorry, it's not going
to work on your system unless your username is math2001):
![The sublime text logo!](file:///home/math2001/.config/sublime-text-3/Packages/MarkdownLivePreview2/live-testing/sublime_text.png)
This is the first image from the local file system, *relative* path!
![The sublime text logo!](sublime_merge.png)
This is the first image from the internet!
![math2001's logo](https://avatars1.githubusercontent.com/u/15224242?s=400&u=53324cf4e303d15032ba53aa41673a2046b3284b&v=4)
[prev]: https://github.com/math2001/MarkdownLivePreview/tree/d4c477749ce7e77b8e9fc85464a2488f003c45bc

View File

@ -1,25 +1,12 @@
# hello world
This is a *test*.
This is a *test*. asdfas
```
import this
# you should try this
```
I'm not sure that it **actually** going to work, but it seems nicer than the [previous version][prev]
<!-- some comment -->
This is the first image from the local file system (absolute path, sorry, it's not going
to work on your system unless your username is math2001):
![The sublime text logo!](file:///home/math2001/.config/sublime-text-3/Packages/MarkdownLivePreview2/live-testing/sublime_text.png)
This is the first image from the local file system, *relative* path!
![The sublime text logo!](sublime_merge.png)
This is the first image from the internet!
![math2001's logo](https://avatars1.githubusercontent.com/u/15224242?s=400&u=53324cf4e303d15032ba53aa41673a2046b3284b&v=4)
[prev]: https://github.com/math2001/MarkdownLivePreview/tree/d4c477749ce7e77b8e9fc85464a2488f003c45bc
this flickering is really annoying...

View File

@ -62,14 +62,16 @@ def markdown2html(markdown, basepath, re_render):
img_element['src'] = base64
# remove comments, because they pollute the console with error messages
for comment_element in soup.find_all(text=lambda text: isinstance(text, bs4.Comment)):
comment_element.extract()
# FIXME: how do tables look? should we use ascii tables?
# FIXME: pre aren't handled by ST3. The require manual adjustment
# FIXME: include a stylesheet
# FIXME: remove the comments, because they pollute the console with error messages
return str(soup)
def get_base64_image(path, re_render):