fix: keep the Save icon hidden on already-saved text notes after swiping#381
Open
MiMoHo wants to merge 1 commit into
Open
fix: keep the Save icon hidden on already-saved text notes after swiping#381MiMoHo wants to merge 1 commit into
MiMoHo wants to merge 1 commit into
Conversation
When autosave is off, saveCurrentNote() updated mCurrentNote.value only for checklists, leaving the stale pre-save text for TYPE_TEXT notes. Since mCurrentNote is the same object reference as mNotes[currentItem], swiping away and back triggered setMenuVisibility -> currentNoteTextChanged, which recomputed showSaveButton from the stale value and made the Save icon reappear on an already-saved note. Add the symmetric else branch so the text note's value is refreshed from the current EditText content after a save, keeping it in sync so the swipe-back recomputation correctly yields false. Fixes FossifyOrg#210
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.
Type of change(s)
What changed and why
With autosave turned off, tapping Save on a text note hid the Save icon correctly, but swiping to another note and back made the icon reappear on a note that had no unsaved changes.
Root cause: Save-icon visibility is computed in
MainActivity.currentNoteTextChanged()asshowSaveButton = newText != mCurrentNote.value, which is re-run on every swipe-back viaTextFragment.setMenuVisibility(true).saveCurrentNote()refreshedmCurrentNote.valueonly forTYPE_CHECKLISTnotes; forTYPE_TEXTnotes it left the stale pre-save value in place. BecausemCurrentNoteis the same object reference asmNotes[currentItem], the stale value survived the page change, so the recomputed comparisonsavedText != stalePreSaveValueevaluated totrueand the Save icon came back.Fix: add the symmetric
elsebranch tosaveCurrentNote()so the in-memory value of a text note is refreshed from the current EditText content right after a save (mCurrentNote.value = getCurrentNoteText() ?: mCurrentNote.value). This mirrors the existing checklist handling and keepsmCurrentNote.valuein sync with what was persisted, so the swipe-back recomputation correctly yieldsfalse. The?: mCurrentNote.valuefallback preserves the old value if the fragment view is unavailable.Tests performed
Built the
fossDebugvariant and verified on an Android 15 (API 35) emulator:Autosave OFF; created 2 text notes; typed in Note A (Save icon appeared), tapped Save (icon hid), swiped to Note B and back to Note A - Save icon stayed hidden (fix); typed a char - Save icon reappeared (dirty detection intact).
Also confirmed
detekt,lint, unit tests and the build all pass locally (CI-equivalent).Closes the following issue(s)
Checklist
CHANGELOG.md(if applicable).Coded with Opus 4.8 ultracode.