Merge pull request #1143 from jellemdekker/feature/keycombo_clear_password_filed

Allow password field to be cleared with Ctrl/Command + backspace, fixes #885
This commit is contained in:
Sebastian Stenzel
2020-04-24 15:27:07 +02:00
committed by GitHub

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();
@@ -99,6 +102,8 @@ public class SecurePasswordField extends TextField {
private void handleKeyEvent(KeyEvent e) {
if (e.getCode() == KeyCode.CAPS) {
updateCapsLocked();
} else if (SHORTCUT_BACKSPACE.match(e)) {
swipe();
}
}