Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OO] Major performance improvements & fixes #12221

Merged
merged 4 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public void insertCitation(XTextCursor cursor, CitationStyle selectedStyle, List

OOText ooText = OOFormat.setLocaleNone(OOText.fromString(formattedCitation));
insertReferences(cursor, entries, ooText, selectedStyle.isNumericStyle());
cursor.collapseToEnd();
}

/**
Expand Down Expand Up @@ -119,7 +118,6 @@ public void insertInTextCitation(XTextCursor cursor, CitationStyle selectedStyle
}
OOText ooText = OOFormat.setLocaleNone(OOText.fromString(finalText));
insertReferences(cursor, List.of(currentEntry), ooText, selectedStyle.isNumericStyle());
cursor.collapseToEnd();
}
}

Expand All @@ -131,9 +129,6 @@ public void insertEmpty(XTextCursor cursor, CitationStyle selectedStyle, List<Bi
throws CreationException, Exception {
OOText emptyOOText = OOFormat.setLocaleNone(OOText.fromString(""));
insertReferences(cursor, entries, emptyOOText, selectedStyle.isNumericStyle());

// Move the cursor to the end of the inserted text - although no need as we don't insert any text, but a good practice
cursor.collapseToEnd();
}

/**
Expand Down Expand Up @@ -165,11 +160,6 @@ public void insertBibliography(XTextCursor cursor, CitationStyle selectedStyle,
OOText ooText = OOFormat.setLocaleNone(OOText.fromString(formattedCitation));

OOTextIntoOO.write(document, cursor, ooText);
// Select the paragraph break
cursor.goLeft((short) 1, true);

// Delete the selected content (paragraph break)
cursor.setString("");
}
} else {
// Ordering will be according to citeproc item data provider (default)
Expand All @@ -180,7 +170,6 @@ public void insertBibliography(XTextCursor cursor, CitationStyle selectedStyle,
OOText ooText = OOFormat.setLocaleNone(OOText.fromString(formattedCitation));
OOTextIntoOO.write(document, cursor, ooText);
}
cursor.collapseToEnd();
}
}

Expand Down Expand Up @@ -208,12 +197,8 @@ private void insertReferences(XTextCursor cursor, List<BibEntry> entries, OOText
CSLReferenceMark mark = markManager.createReferenceMark(entries);
mark.insertReferenceIntoOO(document, cursor, ooText, !preceedingSpaceExists, false);

// Move the cursor to the end of the inserted text
cursor.collapseToEnd();

markManager.setUpdateRequired(isNumericStyle);
readAndUpdateExistingMarks();
cursor.collapseToEnd();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ public static String transformHTML(String html) {
// Clean up any remaining span tags
html = html.replaceAll("</?span[^>]*>", "");

// Convert line breaks to paragraph breaks
html = html.replaceAll("[\n\r]+", "<p></p>");

// Remove leading paragraph tags (including any whitespace after them)
html = html.replaceAll("^\\s*<p>\\s*</p>", "");

// Remove extra trailing paragraph tags when there are multiple (keeping one)
html = html.replaceAll("(?:<p>\\s*</p>\\s*){2,}$", "<p></p>");

return html;
}

Expand Down Expand Up @@ -113,9 +122,9 @@ public static String generateAlphanumericCitation(List<BibEntry> entries, BibDat

/**
* Method to update citation number of a bibliographic entry (to be inserted in the list of references).
* By default, citeproc-java ({@link org.jabref.logic.citationstyle.CitationStyleGenerator#generateBibliography(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateBibliography} always start the numbering of a list of citations with "1".
* If a citation doesn't correspond to the first cited entry, the number should be changed to the relevant current citation number.
* If an entries has been cited before, the colder number should be reused.
* By default, citeproc-java ({@link org.jabref.logic.citationstyle.CitationStyleGenerator#generateBibliography(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateBibliography} always starts the numbering of a list of citations with "1".
* If a citation doesn't correspond to the first cited entry, the number should be changed to the appropriate current citation number.
* The numbers should be globally unique. If an entry has been cited before, the older citation number corresponding to it should be reused.
* The number can be enclosed in different formats, such as "1", "1.", "1)", "(1)" or "[1]".
* <p>
* <b>Precondition:</b> Use ONLY with numeric citation styles.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ private void populateCSLBibTextSection(XTextDocument doc,

// Use CSLCitationOOAdapter to insert the bibliography
cslAdapter.insertBibliography(cursor, citationStyle, entries, bibDatabaseContext, bibEntryTypesManager);
LOGGER.debug("Bibliography inserted using CSLCitationOOAdapter");

cursor.collapseToEnd();
LOGGER.debug("CSL bibliography section population completed");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,114 +159,94 @@ static Stream<Arguments> ooHTMLTransformFromRawBibliography() {

// Non-numeric, parentheses, commas, full stops, slashes, hyphens, colons, italics
Arguments.of(
" Smith, B., Jones, B., & Williams, J. (2016). Title of the test entry. <i>BibTeX Journal</i>, <i>34</i>(3), 45–67. https://doi.org/10.1001/bla.blubb\n",
" Smith, B., Jones, B., & Williams, J. (2016). Title of the test entry. <i>BibTeX Journal</i>, <i>34</i>(3), 45–67. https://doi.org/10.1001/bla.blubb<p></p>",
STYLE_LIST.stream().filter(e -> "American Psychological Association 7th edition".equals(e.getTitle())).findAny().get()
),

// Numeric type "[1]", brackets, newlines
Arguments.of(
" \n" +
" [1] B. Smith, B. Jones, and J. Williams, “Title of the test entry,” <i>BibTeX Journal</i>, vol. 34, no. 3, pp. 45–67, Jul. 2016, doi: 10.1001/bla.blubb.\n" +
" \n",
" [1] B. Smith, B. Jones, and J. Williams, “Title of the test entry,” <i>BibTeX Journal</i>, vol. 34, no. 3, pp. 45–67, Jul. 2016, doi: 10.1001/bla.blubb.<p></p>",
STYLE_LIST.stream().filter(e -> "IEEE".equals(e.getTitle())).findAny().get()
),

// Numeric type "1."
Arguments.of(
" \n" +
" 1. Smith, B., Jones, B., Williams, J.: Title of the test entry. BibTeX Journal. 34, 45–67 (2016). https://doi.org/10.1001/bla.blubb.\n" +
" \n",
" 1. Smith, B., Jones, B., Williams, J.: Title of the test entry. BibTeX Journal. 34, 45–67 (2016). https://doi.org/10.1001/bla.blubb.<p></p>",
STYLE_LIST.stream().filter(e -> "Springer - Lecture Notes in Computer Science".equals(e.getTitle())).findAny().get()
),

Arguments.of(
" Smith, Bill, Bob Jones, and Jeff Williams. 2016. “Title of the Test Entry.” Edited by Phil Taylor. <i>BibTeX Journal</i> 34 (3): 45–67. https://doi.org/10.1001/bla.blubb.\n",
" Smith, Bill, Bob Jones, and Jeff Williams. 2016. “Title of the Test Entry.” Edited by Phil Taylor. <i>BibTeX Journal</i> 34 (3): 45–67. https://doi.org/10.1001/bla.blubb.<p></p>",
STYLE_LIST.stream().filter(e -> "Chicago Manual of Style 17th edition (author-date)".equals(e.getTitle())).findAny().get()
),

// Semicolons
Arguments.of(
" \n" +
" 1. Smith B, Jones B, Williams J. Title of the test entry. Taylor P, editor. BibTeX Journal [Internet]. 2016 Jul;34(3):45–67. Available from: https://github.com/JabRef\n" +
" \n",
" 1. Smith B, Jones B, Williams J. Title of the test entry. Taylor P, editor. BibTeX Journal [Internet]. 2016 Jul;34(3):45–67. Available from: https://github.com/JabRef<p></p>",
STYLE_LIST.stream().filter(e -> "Vancouver".equals(e.getTitle())).findAny().get()
),

Arguments.of(
" \n" +
" 1. Smith, B., Jones, B. & Williams, J. Title of the test entry. <i>BibTeX Journal</i> <b>34</b>, 45–67 (2016).\n" +
" \n",
" 1. Smith, B., Jones, B. & Williams, J. Title of the test entry. <i>BibTeX Journal</i> <b>34</b>, 45–67 (2016).<p></p>",
STYLE_LIST.stream().filter(e -> "Nature".equals(e.getTitle())).findAny().get()
),

Arguments.of(
" \n" +
" 1. Smith B, Jones B, Williams J. Title of the test entry. Taylor P, ed. <i>BibTeX Journal</i>. 2016;34(3):45-67. doi:10.1001/bla.blubb\n" +
" \n",
" 1. Smith B, Jones B, Williams J. Title of the test entry. Taylor P, ed. <i>BibTeX Journal</i>. 2016;34(3):45-67. doi:10.1001/bla.blubb<p></p>",
STYLE_LIST.stream().filter(e -> "American Medical Association 11th edition".equals(e.getTitle())).findAny().get()
),

// Small-caps
Arguments.of(
" <smallcaps>Smith</smallcaps>, <smallcaps>B.</smallcaps>, <smallcaps>Jones</smallcaps>, <smallcaps>B.</smallcaps>, <smallcaps>Williams</smallcaps>, <smallcaps>J.</smallcaps> (2016) Title of the test entry <smallcaps>Taylor</smallcaps>, <smallcaps>P.</smallcaps> (ed.). <i>BibTeX Journal</i>, 34(3), pp. 45–67.\n",
" <smallcaps>Smith</smallcaps>, <smallcaps>B.</smallcaps>, <smallcaps>Jones</smallcaps>, <smallcaps>B.</smallcaps>, <smallcaps>Williams</smallcaps>, <smallcaps>J.</smallcaps> (2016) Title of the test entry <smallcaps>Taylor</smallcaps>, <smallcaps>P.</smallcaps> (ed.). <i>BibTeX Journal</i>, 34(3), pp. 45–67.<p></p>",
STYLE_LIST.stream().filter(e -> "De Montfort University - Harvard".equals(e.getTitle())).findAny().get()
),

// Underlines
Arguments.of(
" Smith, Bill, Bob Jones, and Jeff Williams. “Title of the test entry.” Ed. Phil Taylor. <u>BibTeX Journal</u> 34.3 (2016): 45–67. <https://github.com/JabRef>.\n",
" Smith, Bill, Bob Jones, and Jeff Williams. “Title of the test entry.” Ed. Phil Taylor. <u>BibTeX Journal</u> 34.3 (2016): 45–67. <https://github.com/JabRef>.<p></p>",
STYLE_LIST.stream().filter(e -> "Modern Language Association 7th edition (underline)".equals(e.getTitle())).findAny().get()
),

// Non-breaking spaces
Arguments.of(
" Smith, Bill, Bob Jones, & Jeff Williams, “Title of the test entry,” <i>BibTeX Journal</i>, 2016, vol. 34, no. 3, pp. 45–67.\n",
" Smith, Bill, Bob Jones, & Jeff Williams, “Title of the test entry,” <i>BibTeX Journal</i>, 2016, vol. 34, no. 3, pp. 45–67.<p></p>",
STYLE_LIST.stream().filter(e -> "Histoire & Mesure (Français)".equals(e.getTitle())).findAny().get()
),

// Numeric with a full stop - "1."
Arguments.of(
" \n" +
" 1. Smith, B., Jones, B. and Williams, J. 2016. Title of the test entry. <i>BibTeX Journal</i>. <b>34</b>: 45–67.\n" +
" \n",
" 1. Smith, B., Jones, B. and Williams, J. 2016. Title of the test entry. <i>BibTeX Journal</i>. <b>34</b>: 45–67.<p></p>",
STYLE_LIST.stream().filter(e -> "The Journal of Veterinary Medical Science".equals(e.getTitle())).findAny().get()
),

// Bold text, bold numeric with a full stop - "<BOLD>1."
Arguments.of(
" \n" +
" <b>1</b>. <b>Smith B, Jones B, Williams J</b>. Title of the test entry. <i>BibTeX Journal</i> 2016 ; 34 : 45–67.\n" +
" \n",
" <b>1</b>. <b>Smith B, Jones B, Williams J</b>. Title of the test entry. <i>BibTeX Journal</i> 2016 ; 34 : 45–67.<p></p>",
STYLE_LIST.stream().filter(e -> "Acta Orthopædica Belgica".equals(e.getTitle())).findAny().get()
),

// Naked numeric - "1"
Arguments.of(
" \n" +
" 1 Smith Bill, Jones Bob, Williams Jeff. Title of the test entry. <i>BibTeX Journal</i> 2016;<b>34</b>(3):45–67. Doi: 10.1001/bla.blubb.\n" +
" \n",
" 1 Smith Bill, Jones Bob, Williams Jeff. Title of the test entry. <i>BibTeX Journal</i> 2016;<b>34</b>(3):45–67. Doi: 10.1001/bla.blubb.<p></p>",
STYLE_LIST.stream().filter(e -> "Acta Anaesthesiologica Taiwanica".equals(e.getTitle())).findAny().get()
),

// Numeric in parentheses - "(1)"
Arguments.of(
" \n" +
" (1) Smith, B.; Jones, B.; Williams, J. Title of the Test Entry. <i>BibTeX Journal</i> <b>2016</b>, <i>34</i> (3), 45–67. https://doi.org/10.1001/bla.blubb.\n" +
" \n",
" (1) Smith, B.; Jones, B.; Williams, J. Title of the Test Entry. <i>BibTeX Journal</i> <b>2016</b>, <i>34</i> (3), 45–67. https://doi.org/10.1001/bla.blubb.<p></p>",
STYLE_LIST.stream().filter(e -> "American Chemical Society".equals(e.getTitle())).findAny().get()
),

// Numeric with right parenthesis - "1)"
Arguments.of(
" \n" +
" 1) Smith B., Jones B., Williams J., <i>BibTeX Journal</i>, <b>34</b>, 45–67 (2016).\n" +
" \n",
" 1) Smith B., Jones B., Williams J., <i>BibTeX Journal</i>, <b>34</b>, 45–67 (2016).<p></p>",
STYLE_LIST.stream().filter(e -> "Chemical and Pharmaceutical Bulletin".equals(e.getTitle())).findAny().get()
),

// Numeric in superscript - "<SUPERSCRIPT>1"
Arguments.of(
" <sup>1</sup> B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal <b>34</b>(3), 45–67 (2016).\n",
" <sup>1</sup> B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal <b>34</b>(3), 45–67 (2016).<p></p>",
STYLE_LIST.stream().filter(e -> "American Institute of Physics 4th edition".equals(e.getTitle())).findAny().get()
)
);
Expand Down Expand Up @@ -521,55 +501,43 @@ static Stream<Arguments> updateSingleNumericCitation() {

// Type: "[1]"
Arguments.of(
" \n" +
" [3] B. Smith, B. Jones, and J. Williams, “Title of the test entry,” <i>BibTeX Journal</i>, vol. 34, no. 3, pp. 45–67, Jul. 2016, doi: 10.1001/bla.blubb.\n" +
" \n",
" [3] B. Smith, B. Jones, and J. Williams, “Title of the test entry,” <i>BibTeX Journal</i>, vol. 34, no. 3, pp. 45–67, Jul. 2016, doi: 10.1001/bla.blubb.<p></p>",
STYLE_LIST.stream().filter(e -> "IEEE".equals(e.getTitle())).findAny().get()
),

// Type: "1."
Arguments.of(
" \n" +
" 3. Smith, B., Jones, B. and Williams, J. 2016. Title of the test entry. <i>BibTeX Journal</i>. <b>34</b>: 45–67.\n" +
" \n",
" 3. Smith, B., Jones, B. and Williams, J. 2016. Title of the test entry. <i>BibTeX Journal</i>. <b>34</b>: 45–67.<p></p>",
STYLE_LIST.stream().filter(e -> "The Journal of Veterinary Medical Science".equals(e.getTitle())).findAny().get()
),

// Type:"<BOLD>1."
// Type: "<BOLD>1."
Arguments.of(
" \n" +
" <b>3</b>. <b>Smith B, Jones B, Williams J</b>. Title of the test entry. <i>BibTeX Journal</i> 2016 ; 34 : 45–67.\n" +
" \n",
" <b>3</b>. <b>Smith B, Jones B, Williams J</b>. Title of the test entry. <i>BibTeX Journal</i> 2016 ; 34 : 45–67.<p></p>",
STYLE_LIST.stream().filter(e -> "Acta Orthopædica Belgica".equals(e.getTitle())).findAny().get()
),

// Type: "1"
Arguments.of(
" \n" +
" 3 Smith Bill, Jones Bob, Williams Jeff. Title of the test entry. <i>BibTeX Journal</i> 2016;<b>34</b>(3):45–67. Doi: 10.1001/bla.blubb.\n" +
" \n",
" 3 Smith Bill, Jones Bob, Williams Jeff. Title of the test entry. <i>BibTeX Journal</i> 2016;<b>34</b>(3):45–67. Doi: 10.1001/bla.blubb.<p></p>",
STYLE_LIST.stream().filter(e -> "Acta Anaesthesiologica Taiwanica".equals(e.getTitle())).findAny().get()
),

// Type: "(1)"
Arguments.of(
" \n" +
" (3) Smith, B.; Jones, B.; Williams, J. Title of the Test Entry. <i>BibTeX Journal</i> <b>2016</b>, <i>34</i> (3), 45–67. https://doi.org/10.1001/bla.blubb.\n" +
" \n",
" (3) Smith, B.; Jones, B.; Williams, J. Title of the Test Entry. <i>BibTeX Journal</i> <b>2016</b>, <i>34</i> (3), 45–67. https://doi.org/10.1001/bla.blubb.<p></p>",
STYLE_LIST.stream().filter(e -> "American Chemical Society".equals(e.getTitle())).findAny().get()
),

// Type: "1)"
Arguments.of(
" \n" +
" 3) Smith B., Jones B., Williams J., <i>BibTeX Journal</i>, <b>34</b>, 45–67 (2016).\n" +
" \n",
" 3) Smith B., Jones B., Williams J., <i>BibTeX Journal</i>, <b>34</b>, 45–67 (2016).<p></p>",
STYLE_LIST.stream().filter(e -> "Chemical and Pharmaceutical Bulletin".equals(e.getTitle())).findAny().get()
),

// Type: "<SUPERSCRIPT>1"
Arguments.of(
" <sup>3</sup> B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal <b>34</b>(3), 45–67 (2016).\n",
" <sup>3</sup> B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal <b>34</b>(3), 45–67 (2016).<p></p>",
STYLE_LIST.stream().filter(e -> "American Institute of Physics 4th edition".equals(e.getTitle())).findAny().get()
)
);
Expand Down
Loading