From 858fc28c12f3b405f98b1d02905eb67d53835d72 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sat, 21 Dec 2019 11:08:47 +0100 Subject: [PATCH 1/5] Fixes StringIndexOutOfBoundsException when cutting text --- src/main/java/org/jabref/gui/ClipBoardManager.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/jabref/gui/ClipBoardManager.java b/src/main/java/org/jabref/gui/ClipBoardManager.java index 340fb61ea1a..9dd1f5a91c9 100644 --- a/src/main/java/org/jabref/gui/ClipBoardManager.java +++ b/src/main/java/org/jabref/gui/ClipBoardManager.java @@ -66,11 +66,13 @@ public ClipBoardManager(Clipboard clipboard, java.awt.datatransfer.Clipboard pri * @see Longer text over clipboards */ public static void addX11Support(TextInputControl input) { + /* input.selectedTextProperty().addListener((observable, oldValue, newValue) -> { if (!newValue.isEmpty() && primary != null) { primary.setContents(new StringSelection(newValue), null); } }); + */ input.setOnMouseClicked(event -> { if (event.getButton() == MouseButton.MIDDLE) { input.insertText(input.getCaretPosition(), getContentsPrimary()); From 2303c4b4f2c4f018ccc8add9ffc25b7b47fa78ac Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sat, 21 Dec 2019 16:45:00 +0100 Subject: [PATCH 2/5] Incldue workaround as proposed at https://bugs.openjdk.java.net/browse/JDK-8176270 --- .../java/org/jabref/gui/ClipBoardManager.java | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/jabref/gui/ClipBoardManager.java b/src/main/java/org/jabref/gui/ClipBoardManager.java index 9dd1f5a91c9..6519d785e2d 100644 --- a/src/main/java/org/jabref/gui/ClipBoardManager.java +++ b/src/main/java/org/jabref/gui/ClipBoardManager.java @@ -12,6 +12,9 @@ import java.util.List; import java.util.Optional; +import javafx.application.Platform; +import javafx.beans.InvalidationListener; +import javafx.beans.Observable; import javafx.scene.control.TextInputControl; import javafx.scene.input.Clipboard; import javafx.scene.input.ClipboardContent; @@ -57,22 +60,29 @@ public ClipBoardManager(Clipboard clipboard, java.awt.datatransfer.Clipboard pri } /** - * Add X11 clipboard support to a text input control. - * It is necessary to call this method in every input where you want to use it: - * {@code ClipBoardManager.addX11Support(TextInputControl input);}. + * Add X11 clipboard support to a text input control. It is necessary to call this method in every input where you + * want to use it: {@code ClipBoardManager.addX11Support(TextInputControl input);}. * * @param input the TextInputControl (e.g., TextField, TextArea, and children) where adding this functionality. - * @see Short summary for X11 clipboards - * @see Longer text over clipboards + * @see Short summary for X11 + * clipboards + * @see Longer + * text over clipboards */ public static void addX11Support(TextInputControl input) { - /* - input.selectedTextProperty().addListener((observable, oldValue, newValue) -> { - if (!newValue.isEmpty() && primary != null) { - primary.setContents(new StringSelection(newValue), null); - } - }); - */ + input.selectedTextProperty().addListener( + // using InvalidationListener because of https://bugs.openjdk.java.net/browse/JDK-8176270 + new InvalidationListener() { + @Override + public void invalidated(Observable observable) { + Platform.runLater(() -> { + String newValue = observable.toString(); + if (!newValue.isEmpty() && primary != null) { + primary.setContents(new StringSelection(newValue), null); + } + }); + } + }); input.setOnMouseClicked(event -> { if (event.getButton() == MouseButton.MIDDLE) { input.insertText(input.getCaretPosition(), getContentsPrimary()); From 2426007da63a017d49e22905d3662ad15e3c96f8 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sun, 22 Dec 2019 23:38:13 +0100 Subject: [PATCH 3/5] Try to get right text --- .../java/org/jabref/gui/ClipBoardManager.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/jabref/gui/ClipBoardManager.java b/src/main/java/org/jabref/gui/ClipBoardManager.java index 6519d785e2d..2cf5c0f4bea 100644 --- a/src/main/java/org/jabref/gui/ClipBoardManager.java +++ b/src/main/java/org/jabref/gui/ClipBoardManager.java @@ -72,17 +72,12 @@ public ClipBoardManager(Clipboard clipboard, java.awt.datatransfer.Clipboard pri public static void addX11Support(TextInputControl input) { input.selectedTextProperty().addListener( // using InvalidationListener because of https://bugs.openjdk.java.net/browse/JDK-8176270 - new InvalidationListener() { - @Override - public void invalidated(Observable observable) { - Platform.runLater(() -> { - String newValue = observable.toString(); - if (!newValue.isEmpty() && primary != null) { - primary.setContents(new StringSelection(newValue), null); - } - }); + observable -> Platform.runLater(() -> { + String newValue = ((TextInputControl) observable).getSelectedText(); + if (!newValue.isEmpty() && primary != null) { + primary.setContents(new StringSelection(newValue), null); } - }); + })); input.setOnMouseClicked(event -> { if (event.getButton() == MouseButton.MIDDLE) { input.insertText(input.getCaretPosition(), getContentsPrimary()); From f14c09b607157bda6222eb31cffa967ec8f06249 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sun, 22 Dec 2019 23:41:06 +0100 Subject: [PATCH 4/5] Access input value the right way --- src/main/java/org/jabref/gui/ClipBoardManager.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/ClipBoardManager.java b/src/main/java/org/jabref/gui/ClipBoardManager.java index 2cf5c0f4bea..aae42b57f50 100644 --- a/src/main/java/org/jabref/gui/ClipBoardManager.java +++ b/src/main/java/org/jabref/gui/ClipBoardManager.java @@ -15,6 +15,7 @@ import javafx.application.Platform; import javafx.beans.InvalidationListener; import javafx.beans.Observable; +import javafx.beans.property.ReadOnlyStringProperty; import javafx.scene.control.TextInputControl; import javafx.scene.input.Clipboard; import javafx.scene.input.ClipboardContent; @@ -73,7 +74,7 @@ public static void addX11Support(TextInputControl input) { input.selectedTextProperty().addListener( // using InvalidationListener because of https://bugs.openjdk.java.net/browse/JDK-8176270 observable -> Platform.runLater(() -> { - String newValue = ((TextInputControl) observable).getSelectedText(); + String newValue = input.getSelectedText(); if (!newValue.isEmpty() && primary != null) { primary.setContents(new StringSelection(newValue), null); } From 3efbd862d47c6b07e2b15c6834036b34f2416265 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sun, 22 Dec 2019 23:44:56 +0100 Subject: [PATCH 5/5] Fix checkstyle --- src/main/java/org/jabref/gui/ClipBoardManager.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/org/jabref/gui/ClipBoardManager.java b/src/main/java/org/jabref/gui/ClipBoardManager.java index aae42b57f50..80f66951882 100644 --- a/src/main/java/org/jabref/gui/ClipBoardManager.java +++ b/src/main/java/org/jabref/gui/ClipBoardManager.java @@ -13,9 +13,6 @@ import java.util.Optional; import javafx.application.Platform; -import javafx.beans.InvalidationListener; -import javafx.beans.Observable; -import javafx.beans.property.ReadOnlyStringProperty; import javafx.scene.control.TextInputControl; import javafx.scene.input.Clipboard; import javafx.scene.input.ClipboardContent;