mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-19 19:21:27 +00:00
fixed #567: added drag & drop support for password fields
This commit is contained in:
@@ -11,6 +11,9 @@ package org.cryptomator.ui.controls;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javafx.scene.control.PasswordField;
|
||||
import javafx.scene.input.DragEvent;
|
||||
import javafx.scene.input.Dragboard;
|
||||
import javafx.scene.input.TransferMode;
|
||||
|
||||
/**
|
||||
* Compromise in security. While the text can be swiped, any access to the {@link #getText()} method will create a copy of the String in the heap.
|
||||
@@ -19,6 +22,27 @@ public class SecPasswordField extends PasswordField {
|
||||
|
||||
private static final char SWIPE_CHAR = ' ';
|
||||
|
||||
public SecPasswordField() {
|
||||
this.onDragOverProperty().set(this::handleDragOver);
|
||||
this.onDragDroppedProperty().set(this::handleDragDropped);
|
||||
}
|
||||
|
||||
private void handleDragOver(DragEvent event) {
|
||||
Dragboard dragboard = event.getDragboard();
|
||||
if (dragboard.hasString() && dragboard.getString() != null) {
|
||||
event.acceptTransferModes(TransferMode.COPY);
|
||||
}
|
||||
event.consume();
|
||||
}
|
||||
|
||||
private void handleDragDropped(DragEvent event) {
|
||||
Dragboard dragboard = event.getDragboard();
|
||||
if (dragboard.hasString() && dragboard.getString() != null) {
|
||||
insertText(getCaretPosition(), dragboard.getString());
|
||||
}
|
||||
event.consume();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link #getContent()} uses a StringBuilder, which in turn is backed by a char[].
|
||||
* The delete operation of AbstractStringBuilder closes the gap, that forms by deleting chars, by moving up the following chars.
|
||||
|
||||
Reference in New Issue
Block a user