diff --git a/qt/aqt/addcards.py b/qt/aqt/addcards.py index 7022829db..ac0f65319 100644 --- a/qt/aqt/addcards.py +++ b/qt/aqt/addcards.py @@ -145,7 +145,9 @@ class AddCards(QDialog): # and update editor state self.editor.note = new - self.editor.loadNote() + self.editor.loadNote( + focusTo=min(self.editor.last_field_index or 0, len(new.fields) - 1) + ) def _load_new_note(self, sticky_fields_from: Optional[Note] = None) -> None: note = self._new_note() diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index d4019ab77..6c847b300 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -106,6 +106,9 @@ class Editor: self.note: Optional[Note] = None self.addMode = addMode self.currentField: Optional[int] = None + # Similar to currentField, but not set to None on a blur. May be + # outside the bounds of the current notetype. + self.last_field_index: Optional[int] = None # current card, for card layout self.card: Optional[Card] = None self.setupOuter() @@ -387,7 +390,7 @@ $editorToolbar.then(({{ toolbar }}) => toolbar.appendGroup({{ # focused into field? elif cmd.startswith("focus"): (type, num) = cmd.split(":", 1) - self.currentField = int(num) + self.last_field_index = self.currentField = int(num) gui_hooks.editor_did_focus_field(self.note, self.currentField) elif cmd.startswith("toggleStickyAll"):