Skip to content

Commit 4caf1aa

Browse files
committed
Retain field content when changing note type
1 parent 629bb7d commit 4caf1aa

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

AnkiDroid/src/main/java/com/ichi2/anki/NoteEditorFragment.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2492,7 +2492,17 @@ class NoteEditorFragment :
24922492
if (note == null || addNote) {
24932493
getColUnsafe.run {
24942494
val notetype = notetypes.current()
2495-
Note.fromNotetypeId(this@run, notetype.id)
2495+
val newNote = Note.fromNotetypeId(this@run, notetype.id)
2496+
editorNote?.let {
2497+
if (editorNote!!.fields.size > newNote.fields.size) {
2498+
newNote.fields = editorNote!!.fields.toMutableList()
2499+
} else {
2500+
editorNote!!.fields.forEachIndexed { i, field ->
2501+
newNote.fields[i] = field
2502+
}
2503+
}
2504+
}
2505+
newNote
24962506
}
24972507
} else {
24982508
note
@@ -2891,7 +2901,9 @@ class NoteEditorFragment :
28912901
if (!getColUnsafe.config.getBool(ConfigKey.Bool.ADDING_DEFAULTS_TO_CURRENT_DECK)) {
28922902
deckId = getColUnsafe.defaultsForAdding().deckId
28932903
}
2894-
2904+
for (f in editFields!!) {
2905+
updateField(f)
2906+
}
28952907
refreshNoteData(FieldChangeType.changeFieldCount(shouldReplaceNewlines()))
28962908
setDuplicateFieldStyles()
28972909
}

0 commit comments

Comments
 (0)