Modify the implementation method of "avoiding secondary refresh"
The previous implementation may encounter issues in specific scenarios and could potentially become invalid after Anki updates. Now, the approach has been modified to check whether the note content has been modified, which is a simpler and more understandable method.
This commit is contained in:
parent
8487bb86d0
commit
65cc6c0b12
@ -103,8 +103,8 @@ class EditorPreview(object):
|
|||||||
self.editors.add(editor)
|
self.editors.add(editor)
|
||||||
# The initial loading of notes will also trigger an editing event
|
# The initial loading of notes will also trigger an editing event
|
||||||
# which will cause a second refresh
|
# which will cause a second refresh
|
||||||
# It is disabled here and enabled after the first editing
|
# Caching the content of notes here will be used to determine if the content has changed
|
||||||
editor.need_reload_on_edit = False
|
editor.cached_fields = list(editor.note.fields)
|
||||||
self.refresh(editor)
|
self.refresh(editor)
|
||||||
|
|
||||||
def editor_init_button_hook(self, buttons, editor):
|
def editor_init_button_hook(self, buttons, editor):
|
||||||
@ -134,13 +134,11 @@ class EditorPreview(object):
|
|||||||
|
|
||||||
return f"_showAnswer({json.dumps(a)},'{bodyclass}');"
|
return f"_showAnswer({json.dumps(a)},'{bodyclass}');"
|
||||||
|
|
||||||
def onedit_hook(self, origin):
|
def onedit_hook(self, note):
|
||||||
for editor in self.editors:
|
for editor in self.editors:
|
||||||
if editor.note == origin:
|
if editor.note == note and editor.cached_fields != note.fields:
|
||||||
if editor.need_reload_on_edit:
|
editor.cached_fields = list(note.fields)
|
||||||
self.refresh(editor)
|
self.refresh(editor)
|
||||||
else:
|
|
||||||
editor.need_reload_on_edit = True
|
|
||||||
|
|
||||||
def refresh(self, editor):
|
def refresh(self, editor):
|
||||||
editor.editor_preview.eval(self._obtainCardText(editor.note))
|
editor.editor_preview.eval(self._obtainCardText(editor.note))
|
||||||
|
Loading…
Reference in New Issue
Block a user