Allow password field to be cleared with Ctrl/Command + backspace, implements #885.

This commit is contained in:
jellemdekker
2020-04-24 14:30:19 +02:00
parent b882296c19
commit c204ed2601

View File

@@ -22,6 +22,8 @@ import javafx.scene.control.TextField;
import javafx.scene.input.DragEvent;
import javafx.scene.input.Dragboard;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.TransferMode;
@@ -43,6 +45,7 @@ public class SecurePasswordField extends TextField {
private static final int GROW_BUFFER_SIZE = 50;
private static final String DEFAULT_PLACEHOLDER = "";
private static final String STYLE_CLASS = "secure-password-field";
private static final KeyCodeCombination SHORTCUT_BACKSPACE = new KeyCodeCombination(KeyCode.BACK_SPACE, KeyCombination.SHORTCUT_DOWN);
private final String placeholderChar;
private final BooleanProperty capsLocked = new SimpleBooleanProperty();
@@ -100,6 +103,9 @@ public class SecurePasswordField extends TextField {
if (e.getCode() == KeyCode.CAPS) {
updateCapsLocked();
}
if (SHORTCUT_BACKSPACE.match(e)) {
swipe();
}
}
private void revealPasswordChanged(@SuppressWarnings("unused") Observable observable) {