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:
gugutu 2024-02-25 05:11:17 +08:00 committed by GitHub
parent 8487bb86d0
commit 65cc6c0b12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 8 deletions

View File

@ -103,8 +103,8 @@ class EditorPreview(object):
self.editors.add(editor)
# The initial loading of notes will also trigger an editing event
# which will cause a second refresh
# It is disabled here and enabled after the first editing
editor.need_reload_on_edit = False
# Caching the content of notes here will be used to determine if the content has changed
editor.cached_fields = list(editor.note.fields)
self.refresh(editor)
def editor_init_button_hook(self, buttons, editor):
@ -134,13 +134,11 @@ class EditorPreview(object):
return f"_showAnswer({json.dumps(a)},'{bodyclass}');"
def onedit_hook(self, origin):
def onedit_hook(self, note):
for editor in self.editors:
if editor.note == origin:
if editor.need_reload_on_edit:
self.refresh(editor)
else:
editor.need_reload_on_edit = True
if editor.note == note and editor.cached_fields != note.fields:
editor.cached_fields = list(note.fields)
self.refresh(editor)
def refresh(self, editor):
editor.editor_preview.eval(self._obtainCardText(editor.note))