Skip to content

Fix entry getting deselected after entering in the bibTex source#15441

Merged
Siedlerchr merged 3 commits into
JabRef:mainfrom
Siva-Sai22:fix/#15412
Mar 31, 2026
Merged

Fix entry getting deselected after entering in the bibTex source#15441
Siedlerchr merged 3 commits into
JabRef:mainfrom
Siva-Sai22:fix/#15412

Conversation

@Siva-Sai22

@Siva-Sai22 Siva-Sai22 commented Mar 29, 2026

Copy link
Copy Markdown
Contributor

Related issues and pull requests

Closes #15412

PR Description

Entries were getting deselected after entering a bibTex source and clicking elsewhere. So the shortcuts were not working. Fixed it so that it gets reselected.

Steps to test

  1. Create Entry
  2. Add the bibTex source
@Misc{Hoppenstedt,
  author = {Burkhard Hoppenstedt and Dominik Herrmann},
  title  = {Coding-Unterstützung im Lauf der Zeit},
  url    = {https://gi-radar.de/397-coding-unterstuetzung-im-lauf-der-zeit/},
  year   = {2026},
}
  1. Select field "Citation key"
  2. Press Ctrl+G
Screencast_20260329_191405.webm
Screenshot_20260329_193517

Checklist

  • I own the copyright of the code submitted and I license it under the MIT license
  • I manually tested my changes in running JabRef (always required)
  • I added JUnit tests for changes (if applicable)
  • I added screenshots in the PR description (if change is visible to the user)
  • 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
  • I described the change in CHANGELOG.md in a way that can be understood by the average user (if change is visible to the user)
  • I checked the user documentation for up to dateness and submitted a pull request to our user documentation repository

@qodo-free-for-open-source-projects

Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Fix entry deselection after BibTeX source edit

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Reselect entry after BibTeX source edit completes
• Prevents entry deselection when clicking elsewhere
• Restores keyboard shortcuts functionality after source update
• Updated CHANGELOG with fix documentation
Diagram
flowchart LR
  A["User edits BibTeX source"] --> B["storeSource method executes"]
  B --> C["Entry type changes processed"]
  C --> D["clearAndSelect reselects entry"]
  D --> E["Entry remains selected for shortcuts"]
Loading

Grey Divider

File Changes

1. jabgui/src/main/java/org/jabref/gui/entryeditor/SourceTab.java 🐞 Bug fix +4/-0

Reselect entry after BibTeX source update

• Added code to reselect the entry after BibTeX source is stored
• Calls clearAndSelect() on the main table with the edited entry
• Retrieves active library tab from state manager
• Ensures entry selection is maintained for keyboard shortcuts

jabgui/src/main/java/org/jabref/gui/entryeditor/SourceTab.java


2. CHANGELOG.md 📝 Documentation +1/-0

Document entry deselection bug fix

• Added entry documenting the fix for issue #15412
• Describes the deselection issue and its resolution
• Placed in the Fixed section of the changelog

CHANGELOG.md


Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Mar 29, 2026

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (1) 📎 Requirement gaps (0)

Grey Divider


Action required

1. Unconditional entry reselection 🐞 Bug ≡ Correctness
Description
SourceTab.storeSource now always clears and re-selects outOfFocusEntry in the main table after a
successful parse, which can override the user's current selection. Because storeSource is also
invoked from SourceTab.bindToEntry during entry changes, this can flip selection back to the
previously edited entry (and collapse any multi-selection), breaking normal navigation/selection
behavior.
Code

jabgui/src/main/java/org/jabref/gui/entryeditor/SourceTab.java[R355-357]

+            stateManager.activeTabProperty().get().ifPresent(libraryTab ->
+                    libraryTab.getMainTable().clearAndSelect(outOfFocusEntry)
+            );
Evidence
The new code unconditionally calls MainTable.clearAndSelect(outOfFocusEntry) after a successful
source parse. However, SourceTab.storeSource is called not only on focus loss, but also when the
entry editor switches to a different entry (bindToEntry stores the previous entry). Entry switches
originate from main table selection changes updating StateManager.selectedEntries, which in turn
causes EntryEditor to notify the active tab (potentially SourceTab) about the newly selected
entry—triggering bindToEntry and thus storeSource(previousEntry). Since MainTable.clearAndSelect
clears the selection before selecting a single entry, this can revert the selection back to the
previous entry and/or collapse multi-selection.

jabgui/src/main/java/org/jabref/gui/entryeditor/SourceTab.java[259-264]
jabgui/src/main/java/org/jabref/gui/entryeditor/SourceTab.java[352-360]
jabgui/src/main/java/org/jabref/gui/entryeditor/EntryEditorTab.java[32-42]
jabgui/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java[181-189]
jabgui/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java[518-521]
jabgui/src/main/java/org/jabref/gui/LibraryTab.java[473-503]
jabgui/src/main/java/org/jabref/gui/maintable/MainTable.java[309-323]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`SourceTab.storeSource(...)` unconditionally calls `clearAndSelect(outOfFocusEntry)` after a successful parse. This can override legitimate selection changes (switching to a different entry or maintaining multi-selection), because `storeSource` is also invoked from `SourceTab.bindToEntry(...)` during entry switches.
### Issue Context
The reselection should only happen for the original bug scenario (entry became deselected after interacting with the source editor). When the user has already selected a different entry (or multiple entries), reselection should not run.
### Fix Focus Areas
- jabgui/src/main/java/org/jabref/gui/entryeditor/SourceTab.java[259-264]
- jabgui/src/main/java/org/jabref/gui/entryeditor/SourceTab.java[352-360]
- jabgui/src/test/java/org/jabref/gui/entryeditor/SourceTabTest.java[1-105]
### Suggested fix
- Guard the reselection so it only executes when the current table selection is empty (or otherwise clearly indicates the deselection bug case), e.g. check `stateManager.getSelectedEntries().isEmpty()` before calling `clearAndSelect(outOfFocusEntry)`.
- Ensure the guard prevents reselection when switching to a different entry (selection non-empty and different) and prevents collapsing multi-selection.
- Add/extend a regression test in `SourceTabTest` to cover: selecting entry B after editing entry A in SourceTab does not revert selection back to A.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. storeSource change lacks tests 📘 Rule violation ≡ Correctness
Description
The PR adds new reselection behavior (clearAndSelect) after storing BibTeX source, but no
corresponding test asserts this behavior to prevent regressions. This violates the requirement to
add/update tests when behavior changes.
Code

jabgui/src/main/java/org/jabref/gui/entryeditor/SourceTab.java[R355-357]

+            stateManager.activeTabProperty().get().ifPresent(libraryTab ->
+                    libraryTab.getMainTable().clearAndSelect(outOfFocusEntry)
+            );
Evidence
PR Compliance ID 17 requires updating/adding tests when behavior changes. SourceTab.storeSource
now triggers an additional UI action (clearAndSelect(outOfFocusEntry)), but the existing
SourceTabTest mocks stateManager.activeTabProperty() as empty, so the new branch is never
exercised and no assertion verifies the reselection behavior.

AGENTS.md
jabgui/src/main/java/org/jabref/gui/entryeditor/SourceTab.java[355-357]
jabgui/src/test/java/org/jabref/gui/entryeditor/SourceTabTest.java[50-54]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`SourceTab.storeSource(...)` now reselects the edited entry via `libraryTab.getMainTable().clearAndSelect(outOfFocusEntry)`, but there is no automated test asserting this behavior.
## Issue Context
There is already a `SourceTabTest`, but it currently mocks `stateManager.activeTabProperty()` as empty, so the new `ifPresent(...)` branch is not executed.
## Fix Focus Areas
- jabgui/src/main/java/org/jabref/gui/entryeditor/SourceTab.java[355-357]
- jabgui/src/test/java/org/jabref/gui/entryeditor/SourceTabTest.java[50-54]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

Comment thread jabgui/src/main/java/org/jabref/gui/entryeditor/SourceTab.java Outdated
@testlens-app

This comment has been minimized.

@testlens-app

This comment has been minimized.

@testlens-app

testlens-app Bot commented Mar 29, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: 8ed3328
▶️ Tests: 10210 executed
⚪️ Checks: 55/55 completed


Learn more about TestLens at testlens.app.

@Siedlerchr Siedlerchr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

works fine

@Siedlerchr Siedlerchr added this pull request to the merge queue Mar 31, 2026
@github-actions github-actions Bot added the status: to-be-merged PRs which are accepted and should go into the merge-queue. label Mar 31, 2026
Merged via the queue into JabRef:main with commit 0b2db72 Mar 31, 2026
55 checks passed
@Siva-Sai22 Siva-Sai22 deleted the fix/#15412 branch April 2, 2026 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: no-bot-comments status: to-be-merged PRs which are accepted and should go into the merge-queue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generate Citation Key shortcut does not work anymore

2 participants