From bdfd8c88477004d3637770f97c0277a2c8187835 Mon Sep 17 00:00:00 2001 From: Christoph Date: Tue, 2 Feb 2021 21:41:06 +0100 Subject: [PATCH 1/3] Added keyboard shortcut for merging entries (#7417) Signed-off-by: Siedlerchr Co-authored-by: Kristof Meixner --- src/main/java/org/jabref/gui/actions/StandardActions.java | 2 +- src/main/java/org/jabref/gui/keyboard/KeyBinding.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/actions/StandardActions.java b/src/main/java/org/jabref/gui/actions/StandardActions.java index 70ae5642647..7687ce82990 100644 --- a/src/main/java/org/jabref/gui/actions/StandardActions.java +++ b/src/main/java/org/jabref/gui/actions/StandardActions.java @@ -127,7 +127,7 @@ public enum StandardActions implements Action { EDIT_STRINGS(Localization.lang("Edit string constants"), IconTheme.JabRefIcons.EDIT_STRINGS, KeyBinding.EDIT_STRINGS), FIND_DUPLICATES(Localization.lang("Find duplicates"), IconTheme.JabRefIcons.FIND_DUPLICATES), - MERGE_ENTRIES(Localization.lang("Merge entries"), IconTheme.JabRefIcons.MERGE_ENTRIES), + MERGE_ENTRIES(Localization.lang("Merge entries"), IconTheme.JabRefIcons.MERGE_ENTRIES, KeyBinding.MERGE_ENTRIES), RESOLVE_DUPLICATE_KEYS(Localization.lang("Resolve duplicate citation keys"), Localization.lang("Find and remove duplicate citation keys"), KeyBinding.RESOLVE_DUPLICATE_CITATION_KEYS), CHECK_INTEGRITY(Localization.lang("Check integrity"), KeyBinding.CHECK_INTEGRITY), FIND_UNLINKED_FILES(Localization.lang("Search for unlinked local files"), IconTheme.JabRefIcons.SEARCH, KeyBinding.FIND_UNLINKED_FILES), diff --git a/src/main/java/org/jabref/gui/keyboard/KeyBinding.java b/src/main/java/org/jabref/gui/keyboard/KeyBinding.java index 69872015acb..d6de24e3e62 100644 --- a/src/main/java/org/jabref/gui/keyboard/KeyBinding.java +++ b/src/main/java/org/jabref/gui/keyboard/KeyBinding.java @@ -60,6 +60,7 @@ public enum KeyBinding { HELP("Help", Localization.lang("Help"), "F1", KeyBindingCategory.FILE), IMPORT_INTO_CURRENT_DATABASE("Import into current library", Localization.lang("Import into current library"), "ctrl+I", KeyBindingCategory.FILE), IMPORT_INTO_NEW_DATABASE("Import into new library", Localization.lang("Import into new library"), "ctrl+alt+I", KeyBindingCategory.FILE), + MERGE_ENTRIES("Merge entries", Localization.lang("Merge entries"), "ctrl+M", KeyBindingCategory.TOOLS), NEW_ARTICLE("New article", Localization.lang("New article"), "ctrl+shift+A", KeyBindingCategory.BIBTEX), NEW_BOOK("New book", Localization.lang("New book"), "ctrl+shift+B", KeyBindingCategory.BIBTEX), NEW_ENTRY("New entry", Localization.lang("New entry"), "ctrl+N", KeyBindingCategory.BIBTEX), From 242a494484b7eede94d2c7248ea88d98378deb01 Mon Sep 17 00:00:00 2001 From: Timucin Merdin Date: Wed, 3 Feb 2021 19:03:17 +0100 Subject: [PATCH 2/3] Fix wrong conversion of unicode chars (#7419) * fix wrong character conversion in unicode to latex formatter * fix checkstyle issue * fix typo, add test for unicode to latex formatter * add issue link to changelog --- CHANGELOG.md | 1 + .../formatter/bibtexfields/UnicodeToLatexFormatter.java | 6 +++++- .../logic/util/strings/HTMLUnicodeConversionMaps.java | 3 ++- .../formatter/bibtexfields/UnicodeToLatexFormatterTest.java | 5 +++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c298411e432..5bf9a766b4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue where the file path is invisible in dark theme. [#7382](https://github.com/JabRef/jabref/issues/7382) - We fixed an issue where the secondary sorting is not working for some special fields. [#7015](https://github.com/JabRef/jabref/issues/7015) - We fixed an issue where changing the font size makes the font size field too small. [#7085](https://github.com/JabRef/jabref/issues/7085) +- We fixed an issue where the Unicode to Latex formatter produced wrong results for characters with a codepoint higher than Character.MAX_VALUE. [#7387](https://github.com/JabRef/jabref/issues/7387) ### Removed diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatter.java index cc5fc9f350e..ee7a663da76 100644 --- a/src/main/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatter.java @@ -38,7 +38,11 @@ public String format(String text) { Integer cpNext = result.codePointAt(i + 1); String code = HTMLUnicodeConversionMaps.ESCAPED_ACCENTS.get(cpNext); if (code == null) { - sb.append((char) cpCurrent); + // skip next index to avoid reading surrogate as a separate char + if (!Character.isBmpCodePoint(cpCurrent)) { + i++; + } + sb.appendCodePoint(cpCurrent); } else { sb.append("{\\").append(code).append('{').append((char) cpCurrent).append("}}"); consumed = true; diff --git a/src/main/java/org/jabref/logic/util/strings/HTMLUnicodeConversionMaps.java b/src/main/java/org/jabref/logic/util/strings/HTMLUnicodeConversionMaps.java index e1b0ec49016..f26952c9e0a 100644 --- a/src/main/java/org/jabref/logic/util/strings/HTMLUnicodeConversionMaps.java +++ b/src/main/java/org/jabref/logic/util/strings/HTMLUnicodeConversionMaps.java @@ -760,7 +760,8 @@ public class HTMLUnicodeConversionMaps { {"64259", "", "ffi"}, // ffi ligature (which LaTeX solves by itself) {"64260", "", "ffl"}, // ffl ligature (which LaTeX solves by itself) {"119978", "Oscr", "$\\mathcal{O}$"}, // script capital O -- possibly use \mathscr - {"119984", "Uscr", "$\\mathcal{U}$"} // script capital U -- possibly use \mathscr + {"119984", "Uscr", "$\\mathcal{U}$"}, // script capital U -- possibly use \mathscr + {"120598", "", "$\\epsilon$"}, // mathematical italic epsilon U+1D716 -- requires amsmath }; diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatterTest.java index 5b87c87661d..865c4a8da79 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatterTest.java @@ -24,6 +24,11 @@ void formatMultipleUnicodeCharacters() { assertEquals("{{\\aa}}{\\\"{a}}{\\\"{o}}", formatter.format("\u00E5\u00E4\u00F6")); } + @Test + void formatHighCodepointUnicodeCharacter() { + assertEquals("$\\epsilon$", formatter.format("\uD835\uDF16")); + } + @Test void formatExample() { assertEquals("M{\\\"{o}}nch", formatter.format(formatter.getExampleInput())); From 00894a3378260e7944e5f40144d6608cf3164fe5 Mon Sep 17 00:00:00 2001 From: Timucin Merdin Date: Fri, 5 Feb 2021 19:45:28 +0100 Subject: [PATCH 3/3] add selection copy to preview window (#7421) * add selection copy to preview window * add key in en property file for copy selection * save selected html --- CHANGELOG.md | 1 + .../org/jabref/gui/preview/PreviewPanel.java | 3 ++ .../org/jabref/gui/preview/PreviewViewer.java | 34 ++++++++++++++++++- src/main/resources/l10n/JabRef_en.properties | 1 + 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bf9a766b4d..a695303ffa2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We added some symbols and keybindings to the context menu in the entry editor. [#7268](https://github.com/JabRef/jabref/pull/7268) - We added keybindings for setting and clearing the read status. [#7264](https://github.com/JabRef/jabref/issues/7264) - We added two new fields to track the creation and most recent modification date and time for each entry. [koppor#130](https://github.com/koppor/jabref/issues/130) +- We added a feature that allows the user to copy highlighted text in the preview window. [#6962](https://github.com/JabRef/jabref/issues/6962) ### Changed diff --git a/src/main/java/org/jabref/gui/preview/PreviewPanel.java b/src/main/java/org/jabref/gui/preview/PreviewPanel.java index fa05da300a5..61d366d64e8 100644 --- a/src/main/java/org/jabref/gui/preview/PreviewPanel.java +++ b/src/main/java/org/jabref/gui/preview/PreviewPanel.java @@ -145,6 +145,8 @@ private ContextMenu createPopupMenu() { MenuItem copyPreview = new MenuItem(Localization.lang("Copy preview"), IconTheme.JabRefIcons.COPY.getGraphicNode()); keyBindingRepository.getKeyCombination(KeyBinding.COPY_PREVIEW).ifPresent(copyPreview::setAccelerator); copyPreview.setOnAction(event -> previewView.copyPreviewToClipBoard()); + MenuItem copySelection = new MenuItem(Localization.lang("Copy selection")); + copySelection.setOnAction(event -> previewView.copySelectionToClipBoard()); MenuItem printEntryPreview = new MenuItem(Localization.lang("Print entry preview"), IconTheme.JabRefIcons.PRINTED.getGraphicNode()); printEntryPreview.setOnAction(event -> previewView.print()); MenuItem previousPreviewLayout = new MenuItem(Localization.lang("Previous preview layout")); @@ -156,6 +158,7 @@ private ContextMenu createPopupMenu() { ContextMenu menu = new ContextMenu(); menu.getItems().add(copyPreview); + menu.getItems().add(copySelection); menu.getItems().add(printEntryPreview); menu.getItems().add(new SeparatorMenuItem()); menu.getItems().add(nextPreviewLayout); diff --git a/src/main/java/org/jabref/gui/preview/PreviewViewer.java b/src/main/java/org/jabref/gui/preview/PreviewViewer.java index a44b9ec1d7b..56e571c3819 100644 --- a/src/main/java/org/jabref/gui/preview/PreviewViewer.java +++ b/src/main/java/org/jabref/gui/preview/PreviewViewer.java @@ -38,6 +38,26 @@ public class PreviewViewer extends ScrollPane implements InvalidationListener { private static final Logger LOGGER = LoggerFactory.getLogger(PreviewViewer.class); + // https://stackoverflow.com/questions/5669448/get-selected-texts-html-in-div/5670825#5670825 + private static final String JS_GET_SELECTION_HTML_SCRIPT = "function getSelectionHtml() {" + + " var html = \"\";" + + " if (typeof window.getSelection != \"undefined\") {" + + " var sel = window.getSelection();" + + " if (sel.rangeCount) {" + + " var container = document.createElement(\"div\");" + + " for (var i = 0, len = sel.rangeCount; i < len; ++i) {" + + " container.appendChild(sel.getRangeAt(i).cloneContents());" + + " }" + + " html = container.innerHTML;" + + " }" + + " } else if (typeof document.selection != \"undefined\") {" + + " if (document.selection.type == \"Text\") {" + + " html = document.selection.createRange().htmlText;" + + " }" + + " }" + + " return html;" + + "};" + + "getSelectionHtml();"; private static final String JS_HIGHLIGHT_FUNCTION = "" + " " + @@ -224,12 +244,24 @@ public void copyPreviewToClipBoard() { clipBoardManager.setContent(content); } + public void copySelectionToClipBoard() { + ClipboardContent content = new ClipboardContent(); + content.putString(getSelectionTextContent()); + content.putHtml(getSelectionHtmlContent()); + + clipBoardManager.setContent(content); + } + @Override public void invalidated(Observable observable) { update(); } - public String getSelectionHtmlContent() { + public String getSelectionTextContent() { return (String) previewView.getEngine().executeScript("window.getSelection().toString()"); } + + public String getSelectionHtmlContent() { + return (String) previewView.getEngine().executeScript(JS_GET_SELECTION_HTML_SCRIPT); + } } diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 028ccd9d7ce..420c56cd4b1 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -1325,6 +1325,7 @@ Synchronize\ files=Synchronize files Unabbreviate=Unabbreviate should\ contain\ a\ protocol=should contain a protocol Copy\ preview=Copy preview +Copy\ selection=Copy selection Automatically\ setting\ file\ links=Automatically setting file links Regenerating\ citation\ keys\ according\ to\ metadata=Regenerating citation keys according to metadata Regenerate\ all\ keys\ for\ the\ entries\ in\ a\ BibTeX\ file=Regenerate all keys for the entries in a BibTeX file