From 3015ddd2c1d601454d51540432a93ceb5a1e958a Mon Sep 17 00:00:00 2001 From: Matthias Metelka <62722460+kleinerpirat@users.noreply.github.com> Date: Fri, 3 Dec 2021 22:55:22 +0100 Subject: [PATCH] Fix bug(s) caused by deleting a notetype currently selected in AddCards (#1514) * Remove unneeded old.note_type() call Fixes TypeError thrown after deleting a notetype that's currently selected in the editor. * Handle IndexError on notetype change Occurs in the Add window when changing the notetype via NotetypeChooser from - the notetype that's auto-selected after deleting the currently selected notetype - to a notetype with fewer fields than the auto-selected one * Add return to exception handler to properly ignore the command. --- qt/aqt/addcards.py | 5 ++--- qt/aqt/editor.py | 6 +++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/qt/aqt/addcards.py b/qt/aqt/addcards.py index efeacdb0c..68e1e97af 100644 --- a/qt/aqt/addcards.py +++ b/qt/aqt/addcards.py @@ -139,10 +139,9 @@ class AddCards(QMainWindow): # copy identical fields if field_name in old_fields: new[field_name] = old[field_name] - elif n < len(old.note_type()["flds"]): + elif n < len(old_fields): # set non-identical fields by field index - old_field_name = old.note_type()["flds"][n]["name"] - if old_field_name not in new_fields: + if old_fields[n] not in new_fields: new.fields[n] = old.fields[n] new.tags = old.tags diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index 63c0b9b22..5e4b57960 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -354,7 +354,11 @@ noteEditorPromise.then(noteEditor => noteEditor.toolbar.toolbar.appendGroup({{ print("ignored late blur") return - self.note.fields[ord] = self.mungeHTML(txt) + try: + self.note.fields[ord] = self.mungeHTML(txt) + except IndexError: + print("ignored late blur after notetype change") + return if not self.addMode: self._save_current_note()