Skip to content

Fix state restore bug in FindAndReplaceDialogFragment#19981

Open
lukstbit wants to merge 1 commit intoankidroid:mainfrom
lukstbit:fix_findReplaceBackgroundRestore
Open

Fix state restore bug in FindAndReplaceDialogFragment#19981
lukstbit wants to merge 1 commit intoankidroid:mainfrom
lukstbit:fix_findReplaceBackgroundRestore

Conversation

@lukstbit
Copy link
Member

@lukstbit lukstbit commented Dec 30, 2025

Purpose / Description

Fixes a state restore bug for find and replace fragment where previously selected notes would get ignored when coming back from the background. This is not great because if the user doesn't notice he's going to run the find and replace operation over his entire collection.

Bug reproduction:

Select a row in CardBrowser -> start FindReplace dialog -> notice that the "Selected notes only" is checked -> send dialog to background(with "Don't keep activities" enabled) -> bring the app back to foreground -> at this moment the "Selected notes only" checkbox is unchecked and disabled -> Clicking OK at this point will run the operation against all notes(the previous selection can still be seen in the browser)

Video with the bug:

Screen_recording_20251230_192801.webm

I used our IdsFile implementation to not query the browser's ViewModel. I'm not enthusiastic about this but it works, the browser could probably be changed to fix this but I didn't look into it.

With the code in this PR:

Screen_recording_20251230_191350.webm

Fixes

How Has This Been Tested?

Checked the bug scenario, ran tests.

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

@lukstbit lukstbit mentioned this pull request Dec 30, 2025
4 tasks
@lukstbit lukstbit force-pushed the fix_findReplaceBackgroundRestore branch from bdffe19 to a7cd900 Compare December 30, 2025 17:49
Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to handle IdsFile being missing

This is a common issue

@mikehardy
Copy link
Member

See bug:

🤔 which bug ?

@lukstbit lukstbit added the Needs Author Reply Waiting for a reply from the original author label Jan 21, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2026

Hello 👋, this PR has had no activity for more than 2 weeks and needs a reply from the author. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically

@github-actions github-actions bot added the Stale label Feb 4, 2026
@lukstbit lukstbit removed the Stale label Feb 5, 2026
@github-actions
Copy link
Contributor

Hello 👋, this PR has had no activity for more than 2 weeks and needs a reply from the author. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically

@github-actions github-actions bot added the Stale label Feb 19, 2026
@github-actions github-actions bot closed this Feb 26, 2026
To get the current selected notes the fragment is querying the browser's
ViewModel for the selected notes.

This works most of the times but fails(we lose the selection and will
target everything instead of only the selected notes) when going to
the background and coming back(and fragment gets recreated). At this point
the fragment tries to access again the selected notes but these are not
available as they are being manually restored from a file.

This bug can be seen by using the "Don't keep activities" dev option.

The fix consists in using an IdsFile so the fragment always has a
reference to the selected notes from the moment of its creation.
@lukstbit lukstbit reopened this Feb 28, 2026
@lukstbit lukstbit force-pushed the fix_findReplaceBackgroundRestore branch from a7cd900 to 13e7a13 Compare February 28, 2026 16:48
@lukstbit
Copy link
Member Author

I fixed all raised issues and added an entry about how to reproduce the bug.

@lukstbit lukstbit removed Needs Author Reply Waiting for a reply from the original author Stale labels Feb 28, 2026
Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, cheers!

private fun removeIdsFile() {
runCatching { idsFile.delete() }
.onFailure { throwable ->
Timber.e(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Timber.e(
Timber.w(

@david-allison david-allison added Needs Second Approval Has one approval, one more approval to merge and removed Needs Review labels Mar 4, 2026
@david-allison david-allison added this to the 2.24 release milestone Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Second Approval Has one approval, one more approval to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants