Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Update all associated cardIds of a note #18012

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SttApollo
Copy link

@SttApollo SttApollo commented Feb 24, 2025

This PR fixes a bug in the Note Editor where only the currentEditedCard deckID was being updated when a note was modified, instead of updating all associated cards linked to that note.

To address this issue:

  • Replaced the single-card update (setDeck(listOf(currentEditedCard!!.id), deckId)) with an update that uses all associated card IDs:

The fix has been tested with the following scenarios:

✅ Edited a cloze note three times and verified that all linked cards updated correctly.
✅ Checked behavior when undoing changes, ensuring all cards revert correctly.
✅ Manually tested on:
Emulator (Pixel_3a_API_34_arm64-v8a)

✅ Automated Tests:
Ran the concrete methods FieldEditLineTest and NoteEditorTabOrderTest.kt

ankiDroid-screen_recording.webm

There's a separate issue that I noticed re: Congrats Snackbar, even when I am not "reviewing" the card if the edit is done via AbstractFlashcardViewer and if there are no more cards left in the deck after I change the deck type of a cloze note with two associated cards , the snackbar is triggered as there are no more cards left in the deck.
From the initial investigation, if no card is available in the current deck, the reviewer closes with RESULT_NO_MORE_CARDS, triggering the congrats message. I just wanted to flag this - I can create a new bug for this if it makes sense

Copy link

welcome bot commented Feb 24, 2025

First PR! 🚀 We sincerely appreciate that you have taken the time to propose a change to AnkiDroid! Please have patience with us as we are all volunteers - we will get to this as soon as possible.

Copy link
Member

@BrayanDSO BrayanDSO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small request. The fix looks good to me

@@ -1261,7 +1261,10 @@ class NoteEditor :
// changed did? this has to be done first as remFromDyn() involves a direct write to the database
if (currentEditedCard != null && currentEditedCard!!.currentDeckId() != deckId) {
reloadRequired = true
undoableOp { setDeck(listOf(currentEditedCard!!.id), deckId) }
// Obtain all card IDs for the current note
val allCardIds = editorNote!!.cardIds(getColUnsafe)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val allCardIds = editorNote!!.cardIds(getColUnsafe)
val allCardIds = withCol { editorNote!!.cardIds(this) }

Copy link
Member

@BrayanDSO BrayanDSO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there are many getColUnsafe calls in NoteEditor and because the editor will be gone eventually, I'm approving despite of the change request

@BrayanDSO BrayanDSO added Needs Second Approval Has one approval, one more approval to merge and removed Needs Review labels Feb 24, 2025
@@ -1261,7 +1261,10 @@ class NoteEditor :
// changed did? this has to be done first as remFromDyn() involves a direct write to the database
if (currentEditedCard != null && currentEditedCard!!.currentDeckId() != deckId) {
reloadRequired = true
Copy link
Member

@david-allison david-allison Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this been tested:

  • In the Card Browser in Cards mode
  • From the Reviewer, editing a single card

From a brief overview of the code, this code would update all cards from the note, which is not expected.

@lukstbit lukstbit added the Needs Author Reply Waiting for a reply from the original author label Feb 27, 2025
@SttApollo
Copy link
Author

Hi @david-allison yes I have tested it out in both of the scenarios you mentioned (screen-recording below)
Screen_recording_20250304_122232.webm

My understanding is that a note change should be propagated to all associated cards. ie In the bug issue - a cloze note type has two associated cards and a change in deck type for card #1 should be the same for card #2. Please correct me if I am wrong here and I'll update accordingly.

Copy link
Contributor

Hello 👋, this PR has had no activity for more than 2 weeks and needs a reply from the author. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically

@github-actions github-actions bot added the Stale label Mar 18, 2025
@github-actions github-actions bot closed this Mar 25, 2025
@david-allison david-allison reopened this Mar 26, 2025
@david-allison
Copy link
Member

Only in 'Notes' mode.

If a user is in 'Cards' mode, or edits a single card whilst reviewing, only the deck of the card should be affected

@github-actions github-actions bot removed the Stale label Mar 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Author Reply Waiting for a reply from the original author Needs Second Approval Has one approval, one more approval to merge New contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]: Card Browser - Toggle Notes -> Changing deck in Note Editor only modifies one card
4 participants