LO/OO: Retain in-text nature when re-rendering CSL citations#15369
Conversation
Signed-off-by: subhramit <subhramit.bb@live.in>
Review Summary by QodoRetain in-text citation nature during re-rendering
WalkthroughsDescription• Retain in-text citation nature when re-rendering citations • Track in-text usage state with inTextUsed and inTextNatureChanged flags • Detect transitions between in-text and normal citations • Pass correct in-text flag to bibliography generation Diagramflowchart LR
A["Citation Insertion"] --> B["Track In-Text State"]
B --> C["Detect Nature Change"]
C --> D["Update All Citations"]
D --> E["Generate Bibliography"]
E --> F["Preserve In-Text Nature"]
File Changes1. jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java
|
Code Review by Qodo
1. In-text commas dropped
|
| markManager.setRealTimeNumberUpdateRequired(isNumericStyle); | ||
| markManager.readAndUpdateExistingMarks(); | ||
| updateAllCitationsWithNewStyle(selectedStyle, false); | ||
| updateAllCitationsWithNewStyle(selectedStyle, inTextUsed); |
There was a problem hiding this comment.
1. In-text commas dropped 🐞 Bug ✓ Correctness
When bibliography generation refreshes citations in in-text mode, regenerated mark text does not preserve the trailing comma that was originally inserted inside each single-entry in-text reference mark. This can remove separators between adjacent in-text citations after refresh, changing the document text.
Agent Prompt
### Issue description
Refreshing CSL citations in *in-text* mode during bibliography generation can drop the comma separators between multiple in-text citations inserted in one action. This happens because commas are currently embedded inside each single-entry reference mark’s text during insertion, but `updateAllCitationsWithNewStyle(..., true)` regenerates each mark’s text without preserving any existing trailing punctuation, and then overwrites the mark content.
### Issue Context
- `insertInTextCitation` inserts one reference mark per entry and appends `,` to the text for each entry except the last.
- `insertBibliography` now triggers `updateAllCitationsWithNewStyle(selectedStyle, inTextUsed)`, so in-text refresh is executed during bibliography generation.
- `updateAllCitationsWithNewStyle` (in-text branch) rebuilds mark text purely from regenerated citation strings and overwrites the existing mark text.
### Fix Focus Areas
- jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java[188-235]
- jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java[126-178]
- jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java[283-379]
- jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLReferenceMarkManager.java[257-296]
### Implementation direction
In the in-text refresh loop, read the existing mark text (e.g., `mark.getTextContent().getAnchor().getString()`), detect/preserve a trailing separator (at minimum a trailing comma, ideally a small set like `,`/`;`), and append it to the regenerated citation text when updating that mark. Alternatively (more robust), change insertion so separators are outside the reference mark ranges, but that is a larger behavioral change.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Signed-off-by: subhramit <subhramit.bb@live.in>
✅ All tests passed ✅🏷️ Commit: a54cf78 Learn more about TestLens at testlens.app. |
…15369) * Retain in text nature when re-rendering citations Signed-off-by: subhramit <subhramit.bb@live.in> * Changelog Signed-off-by: subhramit <subhramit.bb@live.in> * Better changelog Signed-off-by: subhramit <subhramit.bb@live.in> --------- Signed-off-by: subhramit <subhramit.bb@live.in>
PR Description
We now support re-rendering existing CSL citations not just based on the change of style selected, but also change its in-text nature (normal vs in-text citations).
This also fixes a bug introduced in #15352 wherein generating bibliography would always refresh citations in the document with their non-in-text form, even if the citations used were in-text. Now they are refreshed, but their nature is retained.
Steps to test
Before:
Cite with in-text IEEE

Generate bibliography (citations refreshed to non-in-text)

Now:
Note
A more robust solution would be to embed the in-text nature in the CSL reference mark itself (like we do in JStyles), and when parsing the existing reference marks from the doc, use that piece of data to set whether
inTextUsedistrue, as otherwise there would be no way to retain the correct information if JabRef is restarted after using in-text citations - and thus generating bibliography would still refresh and overwrite them to normal citations.Current workaround to that (if in-text citations were used and JabRef was restarted and now bibliography is to be generated without inserting another citation) is to insert another in-text citation and remove it to refresh the internal state. Similarly, if in-text citations were used and JabRef is restarted, and now the user wants to change the citation type to normal citations, they have to manually refresh the nature (to in-text and back to normal by inserting citations of respective styles once, and removing them).
Checklist
CHANGELOG.mdin a way that can be understood by the average user (if change is visible to the user)