Fix: Note type switch on Add Note silently discards unsaved-changes warning - #21716
Fix: Note type switch on Add Note silently discards unsaved-changes warning#21716GuTS805 wants to merge 2 commits into
Conversation
david-allison
left a comment
There was a problem hiding this comment.
- Edit + clear a field (
Basic) - Switch to
Basic (and optional reversed card) - Press Back
A save changes dialog is displayed
|
@david-allison Fixed by remapping the baseline by field index instead of freezing it. verified with your exact repro |
cc484e8 to
7a98a59
Compare
|
Snapshot diff report vs
All 70 changed screenshotsAccountActivityScreenshotTest
AddEditReminderDialogScreenshotTest
AllActivitiesScreenshotTest
CardTemplateEditorScreenshotTest
DeckPickerScreenshotTest
DeckPickerTabletScreenshotTest
IntroductionScreenshotTest
MultimediaScreenshotTest
NoteEditorScreenshotTest
PreferencesScreenshotTest
PreviewerScreenshotTest
ReviewRemindersScreenshotTest
ReviewerScreenshotTest
SharedDecksScreenshotTest
StudyScreenScreenshotTest
|
7a98a59 to
6a2f787
Compare
…ote type switch Switching note type on the Add Note screen while unsaved field content exists used to reset the unsaved-changes baseline to the user's own typed text, so backing out lost it with no warning. The baseline is now remapped by field index on a note type switch instead of being reset from current content: existing fields keep their baseline value, and any field the new note type added is treated as baseline-empty. This also fixes a false-positive dialog when a field is typed then cleared before switching to a note type with more fields.
6a2f787 to
4ae05a7
Compare
david-allison
left a comment
There was a problem hiding this comment.
The same issue still seems to occur with <br> in a sticky field
…o newline conversion
|
Found another edge case while testing this fix: if you type into a field that only exists on a larger note type (e.g. field 2 on "Basic optional reversed"), then switch to a smaller type that drops it (e.g. "Basic"), hasUnsavedChanges() returns false and the content is lost with no warning. Root cause: the baseline remap truncates symmetrically with the field content, so a dropped edit leaves no trace to compare against. Leaving this out of this PR to keep the diff minimal, happy to file a follow up if useful. |
Purpose / Description
On the Add Note screen, switching the note type while there is unsaved field content causes the "Discard changes?" warning to be silently skipped when backing out. The typed content is lost without any warning.
Fixes
Approach
addNoteFieldBaseline, which is used byhasUnsavedChanges(), was being reset on every non-NOTE_ADDEDfield refresh while adding a note. This included a simple note type switch.By that point,
populateEditFields()had already carried the user's typed text into the new fields, so the baseline was being updated with the user's own unsaved content and the change was no longer detected.I moved the baseline reset so it only happens when
updateFieldsFromStickyText()actually runs. This is the only case where the repopulated content is genuinely not user-typed.This looks like a regression from #21603, which fixed a related but different sticky-fields false positive.
How Has This Been Tested?
NoteEditorTest.ktthat reproduces the exact scenario: type into a field, switch the note type, and assert thathasUnsavedChanges()remains true.Note
Assisted-by: Claude Sonnet 5 [root cause analysis]