Skip to content

Commit 63880f6

Browse files
authored
Merge pull request #1308 from SatoshiPortal/fix-amount-format-selection-issue
Make sure no selection is added if amount field is unfocused
2 parents d1146b0 + 60a0e7f commit 63880f6

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

lib/core/widgets/inputs/amount_input_formatter.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,13 @@ class AmountInputFormatter extends TextInputFormatter {
6666
// If characters were removed (by leading zero logic or regex truncation)
6767
if (charsRemovedByLeadingZeroLogic > 0) {
6868
// Leading zeros removed: keep cursor at original position
69-
newOffset = oldValue.selection.baseOffset;
69+
newOffset = oldValue.selection.baseOffset.clamp(0, validText.length);
7070
} else if (charsRemovedByRegex > 0) {
7171
// Text truncated by regex (invalid chars or excess decimals): move to end
7272
newOffset = validText.length;
73+
} else if (oldValue.selection.baseOffset == -1) {
74+
// Field was unfocused, preserve the new offset from the caller (dial pad)
75+
newOffset = newValue.selection.baseOffset.clamp(0, validText.length);
7376
} else {
7477
// Normal case: adjust cursor by the text length difference
7578
final lengthDifference = validText.length - oldValue.text.length;

lib/features/receive/ui/screens/receive_amount_screen.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ class _AmountPageState extends State<AmountPage> {
5959
}
6060
});
6161
_amountFocusNode = FocusNode();
62+
63+
// When focus changes, reset selection if unfocused
64+
_amountFocusNode.addListener(() {
65+
if (!_amountFocusNode.hasFocus) {
66+
// Field lost focus, reset selection to end without showing cursor
67+
final currentText = _amountController.text;
68+
_amountController.value = TextEditingValue(
69+
text: currentText,
70+
selection: TextSelection.collapsed(offset: currentText.length),
71+
);
72+
}
73+
});
6274
}
6375

6476
@override

0 commit comments

Comments
 (0)