Skip to content

Commit

Permalink
Merge branch 'master' into fix-texgroup-autoupdate
Browse files Browse the repository at this point in the history
  • Loading branch information
Siedlerchr authored Feb 5, 2021
2 parents 09c7f9b + 00894a3 commit 984a779
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -47,6 +48,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- 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 with TexGroups on Linux systems, where the modification of an aux-file did not trigger an auto-update for TexGroups. Furthermore, the detection of file modifications is now more reliable. [#7412](https://github.com/JabRef/jabref/pull/7412)
- 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

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/actions/StandardActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jabref/gui/keyboard/KeyBinding.java
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/preview/PreviewPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -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);
Expand Down
34 changes: 33 additions & 1 deletion src/main/java/org/jabref/gui/preview/PreviewViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
"<head>" +
" <meta charset=\"UTF-8\">" +
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

};

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down

0 comments on commit 984a779

Please sign in to comment.