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) {