Fix hasUnsavedChanges() false positive with sticky fields - #21603
Open
GuTS805 wants to merge 1 commit into
Open
Conversation
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
Contributor
Author
|
ready for review whenever, lmk if anything needs changing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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