diff --git a/main/ui/src/main/java/org/cryptomator/ui/vaultoptions/GeneralVaultOptionsController.java b/main/ui/src/main/java/org/cryptomator/ui/vaultoptions/GeneralVaultOptionsController.java index 562660f9b..abf233c2b 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/vaultoptions/GeneralVaultOptionsController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/vaultoptions/GeneralVaultOptionsController.java @@ -5,6 +5,7 @@ import org.cryptomator.common.vaults.Vault; import org.cryptomator.ui.common.FxController; import javax.inject.Inject; +import javafx.beans.Observable; import javafx.fxml.FXML; import javafx.scene.control.CheckBox; import javafx.scene.control.ChoiceBox; @@ -36,7 +37,8 @@ public class GeneralVaultOptionsController implements FxController { @FXML public void initialize() { - vaultName.textProperty().bindBidirectional(vault.getVaultSettings().displayName()); + vaultName.textProperty().set(vault.getVaultSettings().displayName().get()); + vaultName.focusedProperty().addListener(this::checkTrimAndTuncateVaultName); vaultName.setTextFormatter(new TextFormatter<>(this::checkVaultNameLength)); unlockOnStartupCheckbox.selectedProperty().bindBidirectional(vault.getVaultSettings().unlockAfterStartup()); actionAfterUnlockChoiceBox.getItems().addAll(WhenUnlocked.values()); @@ -44,6 +46,13 @@ public class GeneralVaultOptionsController implements FxController { actionAfterUnlockChoiceBox.setConverter(new WhenUnlockedConverter(resourceBundle)); } + private void checkTrimAndTuncateVaultName(Observable observable, Boolean wasFocussed, Boolean isFocussed) { + if (!isFocussed) { + var trimmed = vaultName.getText().trim(); + vault.getVaultSettings().displayName().set(trimmed); + } + } + private TextFormatter.Change checkVaultNameLength(TextFormatter.Change change) { if (change.isContentChange() && change.getControlNewText().length() > VAULTNAME_TRUNCATE_THRESHOLD) { return null; // reject any change that would lead to a text exceeding threshold