Skip autosave when entry content hasn't actually changed - #164
Merged
Merged
Conversation
saveIcalEntry() pushed the just-saved (current) entry onto changeBackstack, so its last element always duplicated the current state - the first undo click was a no-op. Worse, onUndo() stamped the restored entry with a fresh lastModified, which the 500ms-debounced autosave pipeline treated as a new edit and re-saved ~500ms later, re-appending it onto changeBackstack and undoing the pop. Undo only appeared to work if clicked faster than that autosave delay. onUndo() now targets the checkpoint before the duplicated top of the stack, and marks its own restore (by the timestamp it just set) so saveIcalEntry() can recognize and skip recording that specific follow-up save instead of racing it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N4dVR3vYtJjSRNLvzXfHrh
Every edit handler in DetailsViewModel unconditionally bumped lastModified whenever it was called, on the assumption it's only called on a genuine change. Two UI call sites break that assumption: opening the date or time picker without touching it re-fires onDateSelected/onTimeUpdated with the picker's seeded (unchanged) value via LaunchedEffect running on first composition, and re-tapping an already-selected color/status re-fires those handlers too. Each still triggered the debounced autosave, which pushed a checkpoint onto changeBackstack and made Undo appear active despite nothing having changed. Rather than guard every handler individually, add one content-equality check (IcalEntry.hasSameContentAs, ignoring id/lastModified/syncState/ etag/href) at the single choke point all edits already funnel through: the debounced autosave pipeline. It's skipped only when this save is undo's own restore (tracked via undoRestoreMarker), since undo legitimately restores content that already matches a backstack entry and that save must still reach the database. TimePickerBottomSheet had a second, independent bug its own LaunchedEffect unconditionally cleared isDateOnly even on that same first, untouched firing, so merely opening the time picker on a date-only entry silently gave it a time. That's a genuine content change no equality check can catch, so its LaunchedEffect now skips its first (seed) firing instead. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N4dVR3vYtJjSRNLvzXfHrh
…hbeeAT/spectacled into implement-undo-functionality
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.
Summary
lastModifiedand triggered the debounced autosave - pushing a spurious checkpoint ontochangeBackstackand making Undo appear active despite nothing having changed.IcalEntry.hasSameContentAs()(ignores id/lastModified/syncState/etag/href) and gated the autosave pipeline inDetailsViewModelon it, so a save is skipped whenever the entry's content genuinely hasn't changed - except for undo's own restore, which is tracked viaundoRestoreMarkerand must still reach the database.TimePickerBottomSheethad an independent bug: itsLaunchedEffectunconditionally clearedisDateOnlyeven on its first, untouched firing, so merely opening the time picker on a date-only entry silently gave it a time. Fixed by skipping that initial firing.Test plan
./gradlew :shared:allTests :androidJournalsApp:lintDebug :androidNotesApp:lintDebug :androidTasksApp:lintDebug🤖 Generated with Claude Code
https://claude.ai/code/session_01N4dVR3vYtJjSRNLvzXfHrh
Generated by Claude Code