preserve focus on notetype change

Closes #1360
This commit is contained in:
Damien Elmes 2021-09-13 15:31:24 +10:00
parent 806fb0f102
commit 18bd821a1f
2 changed files with 7 additions and 2 deletions

View File

@ -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()

View File

@ -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"):