From dc4fd482b5752d0c32dce4699a62b38ef8578cfb Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Fri, 20 Nov 2020 17:17:16 +0100 Subject: [PATCH] Filter any whitespaces when entering text in donationkey form. --- .../preferences/DonationKeyPreferencesController.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/main/ui/src/main/java/org/cryptomator/ui/preferences/DonationKeyPreferencesController.java b/main/ui/src/main/java/org/cryptomator/ui/preferences/DonationKeyPreferencesController.java index e7708af81..a4814ec82 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/preferences/DonationKeyPreferencesController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/preferences/DonationKeyPreferencesController.java @@ -1,5 +1,6 @@ package org.cryptomator.ui.preferences; +import com.google.common.base.CharMatcher; import org.cryptomator.common.LicenseHolder; import org.cryptomator.common.settings.Settings; import org.cryptomator.common.settings.UiTheme; @@ -10,6 +11,7 @@ import javafx.application.Application; import javafx.beans.value.ObservableValue; import javafx.fxml.FXML; import javafx.scene.control.TextArea; +import javafx.scene.control.TextFormatter; @PreferencesScoped public class DonationKeyPreferencesController implements FxController { @@ -32,6 +34,15 @@ public class DonationKeyPreferencesController implements FxController { public void initialize() { donationKeyField.setText(licenseHolder.getLicenseKey().orElse(null)); donationKeyField.textProperty().addListener(this::registrationKeyChanged); + donationKeyField.setTextFormatter(new TextFormatter<>(this::checkVaultNameLength)); + } + + private TextFormatter.Change checkVaultNameLength(TextFormatter.Change change) { + if (change.isContentChange()) { + var strippedText = CharMatcher.whitespace().removeFrom(change.getText()); + change.setText(strippedText); + } + return change; } private void registrationKeyChanged(@SuppressWarnings("unused") ObservableValue observable, @SuppressWarnings("unused") String oldValue, String newValue) {