Only reload note on reopen if empty

This commit is contained in:
Abdo 2025-08-27 02:08:27 +03:00
parent ba881d4e90
commit efe76a24dc
3 changed files with 12 additions and 1 deletions

View file

@ -63,7 +63,7 @@ class NewAddCards(QMainWindow):
) )
def reopen(self, mw: AnkiQt) -> None: def reopen(self, mw: AnkiQt) -> None:
self.editor.reload_note() self.editor.reload_note_if_empty()
def helpRequested(self) -> None: def helpRequested(self) -> None:
openHelp(HelpPage.ADDING_CARD_AND_NOTE) openHelp(HelpPage.ADDING_CARD_AND_NOTE)

View file

@ -435,6 +435,9 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
def reload_note(self) -> None: def reload_note(self) -> None:
self.web.eval("reloadNote();") self.web.eval("reloadNote();")
def reload_note_if_empty(self) -> None:
self.web.eval("reloadNoteIfEmpty();")
def call_after_note_saved( def call_after_note_saved(
self, callback: Callable, keepFocus: bool = False self, callback: Callable, keepFocus: bool = False
) -> None: ) -> None:

View file

@ -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); 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 { function checkNonLegacy(value: any): any | undefined {
if (isLegacy) { if (isLegacy) {
return value; return value;
@ -1139,6 +1146,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
Object.assign(globalThis, { Object.assign(globalThis, {
loadNote, loadNote,
reloadNote, reloadNote,
reloadNoteIfEmpty,
saveSession, saveSession,
setFields, setFields,
setCollapsed, setCollapsed,