group remember after entry deletion
Related issues and pull requests
Closes #15587
PR Description
When deleting an entry, the active group filter was being reset because EntriesRemovedEvent listener was not reapplying the group matches after refreshing the search. Fixed by calling updateGroupMatches() after the refresh.
Steps to test
- Open JabRef
- Select a existing library (or create an example one)
- Delete and entry
- Check if the filter is the same as it was before deleting
Checklist
- [x] I own the copyright of the code submitted and I license it under the MIT license
- [x] I manually tested my changes in running JabRef (always required)
- [x] I added screenshots in the PR description (if change is visible to the user)
- [x] I added a screenshot in the PR description showing a library with a single entry with me as author and as title the issue number
- [x] I described the change in
CHANGELOG.mdin a way that can be understood by the average user (if change is visible to the user)
Video Proof:
https://github.com/user-attachments/assets/1e20461c-4c4d-4780-840d-551ca6f95608
Note that your PR will not be reviewed/accepted until you have gone through the mandatory checks in the description and marked each of them them exactly in the format of - [x] (done), - [ ] (yet to be done) or - [/] (not applicable). Please adhere to our pull request template.
Your pull request conflicts with the target branch.
Please merge with your code. For a step-by-step guide to resolve merge conflicts, see https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/addressing-merge-conflicts/resolving-a-merge-conflict-using-the-command-line.
Looks good to me
Hey, thanks for the review, but what is happening with the checks? Is there smth I should do?
Hey, thanks for the review, but what is happening with the checks? Is there smth I should do?
Those are unrelated to your changes I believe. You can mark the PR ready for review.
PR Summary by Qodo
Preserve active group filter after entry deletion
🐞 Bug fix 📝 Documentation 🕐 10-20 Minutes
AI Description
-
• Reapply active group filtering after entry deletions to prevent filter resets. • Refresh search results and group matches together after removal events. • Document the user-visible fix in the changelog.
Diagram
-
graph TD A["Entry deletion"] --> B(("EntriesRemovedEvent")) --> C["MainTableDataModel"] --> D["Refresh search matches"] --> E["Update group matches"] --> F["Refilter filtered list"]
High-Level Assessment
-
The following are alternative approaches to this PR:
1. Single-pass recompute (search + groups)
-
- ➕ Avoids nested/asynchronous BackgroundTask scheduling
- ➕ Guarantees consistent match-category updates before a single refilter
- ➖ Requires refactoring existing updateSearchMatches/updateGroupMatches helpers
- ➖ Slightly more code churn than the targeted fix
2. Trigger group reapply on success callback
-
- ➕ Keeps recompute ordering explicit (search first, then groups)
- ➕ Avoids scheduling updateGroupMatches from within another background task
- ➖ Still two separate recompute passes
- ➖ Must ensure UI-thread vs background-thread access is correct
Recommendation: The current targeted fix (reapplying group matches after refreshing search results on deletion) is appropriate for a low-risk bug fix. If future issues arise around timing or double-refiltering, consider a single-pass recompute or moving the group refresh to the outer task’s success callback to make ordering and threading more explicit.
-
Files changed (2) +6 / -1
-
Bug fix (1)
+5 / -1-
MainTableDataModel.java
Reapply group matches after entry removals+5/-1
Reapply group matches after entry removals
• Stores the selected groups property on the model and, on EntriesRemovedEvent, captures the current group selection before background execution. After refreshing/clearing search matches, it triggers updateGroupMatches(...) so the active group filter is preserved after deletion.
jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java
Documentation (1)
+1 / -0-
CHANGELOG.md
Document fix for group filter reset after deletion+1/-0
Document fix for group filter reset after deletion
• Adds a changelog entry noting that deleting an entry no longer resets the active group filter (issue #15587).
CHANGELOG.md
-
Code Review by Qodo
🐞 Bugs (1) 📘 Rule violations (2) 📜 Skill insights (0)
1. indexManager final field uninitialized 📘 Rule violation ≡ Correctness ⭐ New
Description
MainTableDataModel introduces a new @Nullable private final IndexManager indexManager; field but neither imports IndexManager nor assigns the field in the constructor, which will cause compilation to fail (e.g., “cannot find symbol” and/or “variable indexManager might not have been initialized”) while also adding likely accidental/unused state. This appears unrelated to the PR’s stated goal and violates the intent of making minimal, non-speculative changes.
Code
jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[67]+ @Nullable private final IndexManager indexManager;
Evidence
The cited MainTableDataModel.java changes add a new final field named indexManager typed as IndexManager, yet the constructor in the same file initializes other members (e.g., selectedGroupsProperty and related fields) without ever setting indexManager. In Java, a final field must be definitely assigned in every constructor (or at the declaration), so leaving it unassigned triggers a compile-time error (“variable indexManager might not have been initialized”); additionally, the preferred notes indicate IndexManager is not imported, which can also produce a “cannot find symbol” compilation error, and the field is not referenced elsewhere in the class, indicating dead/accidental code inconsistent with the PR’s scoped change.
AGENTS.md: Keep methods small, focused, and single-responsibility; avoid duplication and premature abstractionjabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[66-89]jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[72-104]jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[66-69]
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution ## Issue description `MainTableDataModel` declares a new `@Nullable private final IndexManager indexManager;` field, but it is not imported and not assigned in the constructor. This will fail compilation (e.g., `cannot find symbol IndexManager` and/or `variable indexManager might not have been initialized`) and also introduces unnecessary state if the field remains unused. ## Issue Context PR Compliance ID 3 requires minimal, non-speculative changes. This PR’s described change is about reapplying group matches after entry deletion; `indexManager` is unrelated and currently unused within `MainTableDataModel`. The safest resolution is to remove the field unless it was intentionally added and needs proper constructor wiring. ## Fix Focus Areas - jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[66-69] - jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[72-104]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
2. Off-thread group selection read ✓ Resolved 🐞 Bug ☼ Reliability
Description
In the EntriesRemovedEvent handler, selectedGroupsProperty.get() is executed inside BackgroundTask.call (background thread), which can race with UI updates and lead to inconsistent group filtering or runtime threading issues. This was introduced by the new updateGroupMatches(selectedGroupsProperty.get()) call inside the BackgroundTask body.
Code
jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[R282-286]} else { clearSearchMatches(); } + updateGroupMatches(selectedGroupsProperty.get()); }).onSuccess(result -> FilteredListProxy.refilterListReflection(entriesFiltered)).executeWith(taskExecutor);
Evidence
MainTableDataModel invokes updateGroupMatches(selectedGroupsProperty.get()) inside the BackgroundTask.wrap(() -> { ... }) body for EntriesRemovedEvent; BackgroundTask.call is executed on a background thread by UiTaskExecutor (while callbacks like onSuccess run on the FX thread). Since selectedGroupsProperty is a JavaFX ListProperty, reading it from the background thread is not thread-safe and can produce stale/incorrect snapshots or concurrent access issues if the UI updates the selection concurrently.
jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[274-286]jabgui/src/main/java/org/jabref/gui/util/UiTaskExecutor.java[108-114]jabgui/src/main/java/org/jabref/gui/util/UiTaskExecutor.java[186-203]jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[63-88]Best Practice: JavaFX threading rule
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution ## Issue description `selectedGroupsProperty.get()` is called inside `BackgroundTask.wrap(() -> { ... })` in the `EntriesRemovedEvent` listener. Because `BackgroundTask.call()` runs on a background thread, this reads a JavaFX `ListProperty` off the FX thread. ### Issue Context `UiTaskExecutor` executes `BackgroundTask.call()` on a background thread. Accessing JavaFX properties/ObservableLists from that thread can race with UI updates and produce inconsistent results. ### Fix Focus Areas - jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[274-286] ### Suggested fix approach - Read the selected groups on the FX thread *before* starting the background work, and pass an immutable snapshot into the task (e.g., `List<GroupTreeNode> snapshot = List.copyOf(selectedGroupsProperty.get());`). - Then update group matches based on that snapshot (either by overloading `updateGroupMatches` to accept `List<GroupTreeNode>` or by inlining the matcher recomputation in the same task without touching `selectedGroupsProperty` off-thread).
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
3. No test for deletion filter 📘 Rule violation ☼ Reliability
Description
The PR changes deletion behavior by reapplying group matches after an EntriesRemovedEvent, but no regression test is added/updated to cover this behavior. This increases the risk of the bug returning without detection.
Code
jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[R274-287]public void listen(EntriesRemovedEvent removedEntriesEvent) { // When entries are removed, we need to refresh the search matches // to ensure the filtered list is properly updated and doesn't show stale entries + ObservableList<GroupTreeNode> selectedGroups = selectedGroupsProperty.get(); BackgroundTask.wrap(() -> { // Re-run the current search to update the filtered results if (searchQueryProperty.get().isPresent()) { setSearchMatches(indexManager.search(searchQueryProperty.get().get())); } else { clearSearchMatches(); } + updateGroupMatches(selectedGroups); }).onSuccess(result -> FilteredListProxy.refilterListReflection(entriesFiltered)).executeWith(taskExecutor); }
Evidence
PR Compliance ID 19 requires tests to be added/updated for behavior changes. The PR introduces a behavioral change in the EntriesRemovedEvent listener (updateGroupMatches(...) is newly invoked after refreshing search matches), but the existing MainTableDataModelTest does not cover entry deletion/group-filter retention behavior.
AGENTS.md: AGENTS.md: AGENTS.md: AGENTS.mdjabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[273-287]jabgui/src/test/java/org/jabref/gui/maintable/MainTableDataModelTest.java[28-64]
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution ## Issue description Behavior was changed so that after `EntriesRemovedEvent`, group matches are reapplied. This should be covered by a regression test to prevent future regressions. ## Issue Context The reported bug is: deleting an entry reset the active group filter. The PR fixes this by calling `updateGroupMatches()` after refreshing search results. ## Fix Focus Areas - jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[273-287] - jabgui/src/test/java/org/jabref/gui/maintable/MainTableDataModelTest.java[1-64] ## Suggested direction - Add a test that sets up a `MainTableDataModel` with a selected group filter, removes an entry (or simulates `EntriesRemovedEvent`), and asserts the filtered list/group match state remains consistent after deletion.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
4. Redundant refilter/background work 🐞 Bug ➹ Performance
Description
The EntriesRemovedEvent handler schedules a BackgroundTask that refilters on success, and also calls updateGroupMatches(), which schedules another BackgroundTask that refilters again. This adds extra work on every deletion and can cause unnecessary UI churn.
Code
jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[R285-286]+ updateGroupMatches(selectedGroupsProperty.get()); }).onSuccess(result -> FilteredListProxy.refilterListReflection(entriesFiltered)).executeWith(taskExecutor);
Evidence
The EntriesRemovedEvent handler runs a BackgroundTask and refilters the table in its onSuccess. updateGroupMatches() also creates its own BackgroundTask and refilters in its onSuccess. Calling updateGroupMatches() from within the deletion refresh path therefore creates two tasks and two refilter operations for a single delete.
jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[274-286]jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[167-174]
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution ## Issue description On entry deletion, the code triggers multiple BackgroundTasks/refilters: one for refreshing search matches and another inside `updateGroupMatches()`. This does redundant work per deletion. ### Issue Context Both tasks end with `FilteredListProxy.refilterListReflection(entriesFiltered)`. ### Fix Focus Areas - jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[167-174] - jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[274-286] ### Suggested fix approach - During `EntriesRemovedEvent`, perform both the search-match refresh and the group-match recomputation within the *same* BackgroundTask call body, and refilter once in the enclosing task’s `onSuccess`. - Optionally refactor `updateGroupMatches` into a `updateGroupMatchesInternal(...)` that does not schedule its own task, so it can be reused by both the selection listener and the deletion path.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Previous review results
Review updated until commit https://github.com/JabRef/jabref/commit/7a939e495331854bd9c2a4887cbcec838b0bbef1
Results up to commit N/A
🐞 Bugs (1) 📘 Rule violations (1) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)
1. Off-thread group selection read ✓ Resolved 🐞 Bug ☼ Reliability
Description
In the EntriesRemovedEvent handler, selectedGroupsProperty.get() is executed inside BackgroundTask.call (background thread), which can race with UI updates and lead to inconsistent group filtering or runtime threading issues. This was introduced by the new updateGroupMatches(selectedGroupsProperty.get()) call inside the BackgroundTask body.
Code
jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[R282-286]} else { clearSearchMatches(); } + updateGroupMatches(selectedGroupsProperty.get()); }).onSuccess(result -> FilteredListProxy.refilterListReflection(entriesFiltered)).executeWith(taskExecutor);
Evidence
MainTableDataModel invokes updateGroupMatches(selectedGroupsProperty.get()) inside the BackgroundTask.wrap(() -> { ... }) body for EntriesRemovedEvent; BackgroundTask.call is executed on a background thread by UiTaskExecutor (while callbacks like onSuccess run on the FX thread). Since selectedGroupsProperty is a JavaFX ListProperty, reading it from the background thread is not thread-safe and can produce stale/incorrect snapshots or concurrent access issues if the UI updates the selection concurrently.
jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[274-286]jabgui/src/main/java/org/jabref/gui/util/UiTaskExecutor.java[108-114]jabgui/src/main/java/org/jabref/gui/util/UiTaskExecutor.java[186-203]jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[63-88]Best Practice: JavaFX threading rule
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution ## Issue description `selectedGroupsProperty.get()` is called inside `BackgroundTask.wrap(() -> { ... })` in the `EntriesRemovedEvent` listener. Because `BackgroundTask.call()` runs on a background thread, this reads a JavaFX `ListProperty` off the FX thread. ### Issue Context `UiTaskExecutor` executes `BackgroundTask.call()` on a background thread. Accessing JavaFX properties/ObservableLists from that thread can race with UI updates and produce inconsistent results. ### Fix Focus Areas - jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[274-286] ### Suggested fix approach - Read the selected groups on the FX thread *before* starting the background work, and pass an immutable snapshot into the task (e.g., `List<GroupTreeNode> snapshot = List.copyOf(selectedGroupsProperty.get());`). - Then update group matches based on that snapshot (either by overloading `updateGroupMatches` to accept `List<GroupTreeNode>` or by inlining the matcher recomputation in the same task without touching `selectedGroupsProperty` off-thread).
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
2. No test for deletion filter 📘 Rule violation ☼ Reliability
Description
The PR changes deletion behavior by reapplying group matches after an EntriesRemovedEvent, but no regression test is added/updated to cover this behavior. This increases the risk of the bug returning without detection.
Code
jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[R274-287]public void listen(EntriesRemovedEvent removedEntriesEvent) { // When entries are removed, we need to refresh the search matches // to ensure the filtered list is properly updated and doesn't show stale entries + ObservableList<GroupTreeNode> selectedGroups = selectedGroupsProperty.get(); BackgroundTask.wrap(() -> { // Re-run the current search to update the filtered results if (searchQueryProperty.get().isPresent()) { setSearchMatches(indexManager.search(searchQueryProperty.get().get())); } else { clearSearchMatches(); } + updateGroupMatches(selectedGroups); }).onSuccess(result -> FilteredListProxy.refilterListReflection(entriesFiltered)).executeWith(taskExecutor); }
Evidence
PR Compliance ID 19 requires tests to be added/updated for behavior changes. The PR introduces a behavioral change in the EntriesRemovedEvent listener (updateGroupMatches(...) is newly invoked after refreshing search matches), but the existing MainTableDataModelTest does not cover entry deletion/group-filter retention behavior.
AGENTS.md: AGENTS.mdjabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[273-287]jabgui/src/test/java/org/jabref/gui/maintable/MainTableDataModelTest.java[28-64]
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution ## Issue description Behavior was changed so that after `EntriesRemovedEvent`, group matches are reapplied. This should be covered by a regression test to prevent future regressions. ## Issue Context The reported bug is: deleting an entry reset the active group filter. The PR fixes this by calling `updateGroupMatches()` after refreshing search results. ## Fix Focus Areas - jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[273-287] - jabgui/src/test/java/org/jabref/gui/maintable/MainTableDataModelTest.java[1-64] ## Suggested direction - Add a test that sets up a `MainTableDataModel` with a selected group filter, removes an entry (or simulates `EntriesRemovedEvent`), and asserts the filtered list/group match state remains consistent after deletion.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
3. Redundant refilter/background work 🐞 Bug ➹ Performance
Description
The EntriesRemovedEvent handler schedules a BackgroundTask that refilters on success, and also calls updateGroupMatches(), which schedules another BackgroundTask that refilters again. This adds extra work on every deletion and can cause unnecessary UI churn.
Code
jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[R285-286]+ updateGroupMatches(selectedGroupsProperty.get()); }).onSuccess(result -> FilteredListProxy.refilterListReflection(entriesFiltered)).executeWith(taskExecutor);
Evidence
The EntriesRemovedEvent handler runs a BackgroundTask and refilters the table in its onSuccess. updateGroupMatches() also creates its own BackgroundTask and refilters in its onSuccess. Calling updateGroupMatches() from within the deletion refresh path therefore creates two tasks and two refilter operations for a single delete.
jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[274-286]jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[167-174]
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution ## Issue description On entry deletion, the code triggers multiple BackgroundTasks/refilters: one for refreshing search matches and another inside `updateGroupMatches()`. This does redundant work per deletion. ### Issue Context Both tasks end with `FilteredListProxy.refilterListReflection(entriesFiltered)`. ### Fix Focus Areas - jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[167-174] - jabgui/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java[274-286] ### Suggested fix approach - During `EntriesRemovedEvent`, perform both the search-match refresh and the group-match recomputation within the *same* BackgroundTask call body, and refilter once in the enclosing task’s `onSuccess`. - Optionally refactor `updateGroupMatches` into a `updateGroupMatchesInternal(...)` that does not schedule its own task, so it can be reused by both the selection listener and the deletion path.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Hi, any interest to continue here? Otherwise we'll close
Hi, any interest to continue here? Otherwise we'll close
Hey, yes. I will submit a commit that solves that comment today
Hey, how can i resolve this conflicts? I didn't change anything in those csl-styles files
https://devdocs.jabref.org/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/trouble-shooting.html#changes-in-jablibsrcmainresourcescsl-styles-are-shown
Persistent review updated to latest commit https://github.com/JabRef/jabref/commit/9bd7428590bfaadfe74f2a26c2fb1b7bda4c6e49
Persistent review updated to latest commit 9bd7428
what should I do to solve this? If I understood what it is saying, the bot wants me to write some tests for this fix
The bot is giving you some feedback on critical areas that you should take a closer look. I am not sure if it's possible to write a test but at least take a look at the thing with UI sync
The bot is giving you some feedback on critical areas that you should take a closer look. I am not sure if it's possible to write a test but at least take a look at the thing with UI
Looking at what the boot is complaining about, this "Action Required" is about a code that I already changed and was supposed to correct this.
The bot is giving you some feedback on critical areas that you should take a closer look. I am not sure if it's possible to write a test but at least take a look at the thing with UI
Looking at what the boot is complaining about, this "Action Required" is about a code that I already changed and was supposed to correct this.
Are you saying the test mentioned by the bot is outdated?
The bot is giving you some feedback on critical areas that you should take a closer look. I am not sure if it's possible to write a test but at least take a look at the thing with UI
Looking at what the boot is complaining about, this "Action Required" is about a code that I already changed and was supposed to correct this.
Are you saying the test mentioned by the bot is outdated?
Not the test, but the code itself. If I'm not seeing it wrong, the newest version of this code is not what the bot is complaining there.
The bot is taking in consideration this code: "selectedGroupsProperty.get()"
But seeing this review, I changed it to get this properties before entering the UI thread, removing the possibility to race conditions, as it said in the review.
If you take a look on the files changed tab, the latest commit about this was:
So, if I'm not wrong here, it should consider the version with "selectedGroups" variable (without the .get()), and that should fix this issue. Please let me know if I'm mistaken here
The requested changes were not addressed for 10 days. Please follow-up in the next 10 days or your PR will be automatically closed. You can check the contributing guidelines for hints on the pull request process.
Do not mark a PR as ready-for-review if changes are required. Address the changes first.
Code review by qodo was updated up to the latest commit https://github.com/JabRef/jabref/commit/7a939e495331854bd9c2a4887cbcec838b0bbef1