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

Fixes StringIndexOutOfBoundsException when cutting text #5776

Merged
merged 6 commits into from
Dec 23, 2019
Merged
Changes from all 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
25 changes: 15 additions & 10 deletions src/main/java/org/jabref/gui/ClipBoardManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.List;
import java.util.Optional;

import javafx.application.Platform;
import javafx.scene.control.TextInputControl;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
Expand Down Expand Up @@ -57,20 +58,24 @@ 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 <a href="https://www.uninformativ.de/blog/postings/2017-04-02/0/POSTING-en.html">Short summary for X11 clipboards</a>
* @see <a href="https://unix.stackexchange.com/questions/139191/whats-the-difference-between-primary-selection-and-clipboard-buffer/139193#139193">Longer text over clipboards</a>
* @see <a href="https://www.uninformativ.de/blog/postings/2017-04-02/0/POSTING-en.html">Short summary for X11
* clipboards</a>
* @see <a href="https://unix.stackexchange.com/questions/139191/whats-the-difference-between-primary-selection-and-clipboard-buffer/139193#139193">Longer
* text over clipboards</a>
*/
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
observable -> Platform.runLater(() -> {
String newValue = input.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());
Expand Down