Improve algorithm to cover pasted text
MODIFY
WalletWasabi.Fluent/Controls/CurrencyEntryBox.axaml.cs
WalletWasabi.Fluent/Controls/CurrencyEntryBox.axaml.cs
@@ -128,13 +128,8 @@ public class CurrencyEntryBox : TextBox
protected override void OnTextInput(TextInputEventArgs e)
{
- if (Text.Trim() == "" && e.Text == ".")
- {
- InsertImplicitZeroForDecimal(e);
- return;
- }
-
var input = e.Text ?? "";
+
// Reject space char input when there's no text.
if (string.IsNullOrWhiteSpace(Text) && string.IsNullOrWhiteSpace(input))
{
@@ -143,6 +138,13 @@ public class CurrencyEntryBox : TextBox
return;
}
+ if (input.StartsWith(".") && (string.IsNullOrWhiteSpace(Text) || SelectedText == Text))
+ {
+ InsertImplicitZeroForDecimal(e);
+ base.OnTextInput(e);
+ return;
+ }
+
var preComposedText = PreComposeText(input);
decimal fiatValue = 0;
@@ -160,9 +162,8 @@ public class CurrencyEntryBox : TextBox
private void InsertImplicitZeroForDecimal(TextInputEventArgs e)
{
- e.Text = "0.";
+ e.Text = "0" + e.Text;
CaretIndex = e.Text.Length;
- base.OnTextInput(e);
}
private bool ValidateEntryText(string preComposedText)

Improve algorithm to cover pasted text