Skip to content

Fix hasUnsavedChanges() false positive with sticky fields - #21603

Open
GuTS805 wants to merge 1 commit into
ankidroid:mainfrom
GuTS805:fix/note-editor-sticky-field-unsaved-changes-21564
Open

Fix hasUnsavedChanges() false positive with sticky fields#21603
GuTS805 wants to merge 1 commit into
ankidroid:mainfrom
GuTS805:fix/note-editor-sticky-field-unsaved-changes-21564

Conversation

@GuTS805

@GuTS805 GuTS805 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Fixes #21564

Purpose / Description

The note editor was treating a sticky field as an "unsaved change" even when the user hadnt actually done anything. Since sticky fields carry their value forward from the previous note on purpose, the old check (any field non-empty = changed) basically always fired once a sticky field had content in it. So youd save a note, sticky field carries over like its supposed to, and then just trying to leave the screen would pop up a discard-changes warning for no reason.

Approach

Instead of checking "is any field non-empty", now it captures a baseline of what the fields look like right after theyre (re)populated (fresh load or right after a save-and-continue), and compares the current fields against that baseline. So sticky content that was never touched by the user doesnt count as an edit anymore, only stuff that actually changed from that baseline does.

How Has This Been Tested?

Added a Robolectric test that marks a field sticky, saves a note, and checks hasUnsavedChanges() right after (should be false since nothing was typed). Also checked the case where the user types into the other field and then reverts it back to empty - should still be false since net-net nothing changed. Confirmed the test fails on the old code and passes with the fix, also reverted the fix temporarily to make sure only this one test breaks and nothing else does.

Checklist

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

fieldsEdited() was checking whether any field was non-empty, but sticky
fields are non-empty by design (carried over from the previous note).
This meant the note editor could report unsaved changes right after
saving, before the user touched anything.

Now compares current field values against a baseline captured right
after fields were last (re)populated, so sticky-carried-over content
is no longer mistaken for an actual edit.

Fixes ankidroid#21564
@GuTS805

GuTS805 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

ready for review whenever, lmk if anything needs changing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hasUnsavedChanges() thinks theres unsaved changes right after saving a note with a sticky field

1 participant