From efe76a24dc150ae8b708fa5fc3c2727262d4f726 Mon Sep 17 00:00:00 2001 From: Abdo Date: Wed, 27 Aug 2025 02:08:27 +0300 Subject: [PATCH] Only reload note on reopen if empty --- qt/aqt/addcards.py | 2 +- qt/aqt/editor.py | 3 +++ ts/routes/editor/NoteEditor.svelte | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/qt/aqt/addcards.py b/qt/aqt/addcards.py index 629f81679..53f1cdd12 100644 --- a/qt/aqt/addcards.py +++ b/qt/aqt/addcards.py @@ -63,7 +63,7 @@ class NewAddCards(QMainWindow): ) def reopen(self, mw: AnkiQt) -> None: - self.editor.reload_note() + self.editor.reload_note_if_empty() def helpRequested(self) -> None: openHelp(HelpPage.ADDING_CARD_AND_NOTE) diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index 3cc171b91..9db3fed36 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -435,6 +435,9 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too def reload_note(self) -> None: self.web.eval("reloadNote();") + def reload_note_if_empty(self) -> None: + self.web.eval("reloadNoteIfEmpty();") + def call_after_note_saved( self, callback: Callable, keepFocus: bool = False ) -> None: diff --git a/ts/routes/editor/NoteEditor.svelte b/ts/routes/editor/NoteEditor.svelte index e8ed2ad47..0b1885dc5 100644 --- a/ts/routes/editor/NoteEditor.svelte +++ b/ts/routes/editor/NoteEditor.svelte @@ -1094,6 +1094,13 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html await loadNote(note!.id, notetypeMeta.id, 0, null, reviewerCard?.id ?? null); } + async function reloadNoteIfEmpty() { + const isEmpty = (await noteFieldsCheck(note!)).state == NoteFieldsCheckResponse_State.EMPTY; + if (isEmpty) { + await loadNote(note!.id, notetypeMeta.id, 0, null, reviewerCard?.id ?? null, true); + } + } + function checkNonLegacy(value: any): any | undefined { if (isLegacy) { return value; @@ -1139,6 +1146,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html Object.assign(globalThis, { loadNote, reloadNote, + reloadNoteIfEmpty, saveSession, setFields, setCollapsed,