Skip to content

Commit

Permalink
fix(note-editor): filtered card sent home after edit
Browse files Browse the repository at this point in the history
If a card in a filtered deck was edited, it was
returned home

Cause: b455b7b

Fixes 16522
  • Loading branch information
david-allison committed Jun 4, 2024
1 parent 8d5d3da commit b5acdca
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion AnkiDroid/src/main/java/com/ichi2/anki/NoteEditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ class NoteEditor : AnkiActivity(), DeckSelectionListener, SubtitleListener, Tags
// Regular changes in note content
var modified = false
// changed did? this has to be done first as remFromDyn() involves a direct write to the database
if (currentEditedCard != null && currentEditedCard!!.did != deckId) {
if (currentEditedCard != null && currentEditedCard!!.currentDeckId().did != deckId) {
reloadRequired = true
undoableOp { setDeck(listOf(currentEditedCard!!.id), deckId) }
// refresh the card object to reflect the database changes from above
Expand All @@ -1080,6 +1080,7 @@ class NoteEditor : AnkiActivity(), DeckSelectionListener, SubtitleListener, Tags
// then set the card ID to the new deck
currentEditedCard!!.did = deckId
modified = true
Timber.d("deck ID updated to '%d'", deckId)
}
// now load any changes to the fields from the form
for (f in editFields!!) {
Expand Down
20 changes: 20 additions & 0 deletions AnkiDroid/src/test/java/com/ichi2/anki/NoteEditorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,26 @@ class NoteEditorTest : RobolectricTest() {
}
}

@Test
fun `editing card in filtered deck retains deck`() = runTest {
val homeDeckId = addDeck("A")
val note = addNoteUsingBasicModel().updateCards { did = homeDeckId }
moveToDynamicDeck(note)

// ensure note is correctly setup
assertThat("home deck", note.firstCard().oDid, equalTo(homeDeckId))
assertThat("current deck", note.firstCard().did, not(equalTo(homeDeckId)))

getNoteEditorEditingExistingBasicNote(note, REVIEWER, NoteEditor::class.java).apply {
setField(0, "Hello")
saveNote()
}

// ensure note is correctly setup
assertThat("after: home deck", note.firstCard().oDid, equalTo(homeDeckId))
assertThat("after: current deck", note.firstCard().did, not(equalTo(homeDeckId)))
}

private fun moveToDynamicDeck(note: Note): DeckId {
val dyn = addDynamicDeck("All")
col.decks.select(dyn)
Expand Down

0 comments on commit b5acdca

Please sign in to comment.