From 3aa00076c67f0b82881968ef3f8b53a248e8a2b3 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Thu, 25 May 2023 16:15:38 +0200 Subject: [PATCH] trim leading and trailing whitespace from pay to address field --- .../sparrow/wallet/PaymentController.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java index 2498282c..7bd322ad 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java @@ -210,6 +210,18 @@ public class PaymentController extends WalletFormController implements Initializ revalidateAmount(); }); + address.setTextFormatter(new TextFormatter<>(change -> { + String controlNewText = change.getControlNewText(); + if(!controlNewText.equals(controlNewText.trim())) { + String text = change.getText(); + String newText = text.trim(); + int caretPos = change.getCaretPosition() - text.length() + newText.length(); + change.setText(newText); + change.selectRange(caretPos, caretPos); + } + return change; + })); + address.textProperty().addListener((observable, oldValue, newValue) -> { address.leftProperty().set(null);