Skip to content

Commit 8e42644

Browse files
committed
Bug fix 3279 suggested by oenarap
1 parent 63cbb4a commit 8e42644

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

Microsoft.Toolkit.Uwp.UI/Extensions/TextBox/TextBoxExtensions.Mask.Internals.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,18 @@ private static void Textbox_TextChanging(TextBox textbox, TextBoxTextChangingEve
297297
// case adding data at the end of the textbox
298298
if (oldSelectionStart >= oldText.Length && !isDeleteOrBackspace)
299299
{
300-
textbox.Text = textbox.Text.Substring(0, oldText.Length);
301-
if (oldText.Length >= 0)
300+
// ignore change(s) if oldtext is a substring of new text value
301+
if (textbox.Text.Contains(oldText, StringComparison.OrdinalIgnoreCase))
302302
{
303-
textbox.SelectionStart = oldText.Length;
304-
}
303+
textbox.Text = oldText;
305304

306-
return;
305+
if (oldText.Length >= 0)
306+
{
307+
textbox.SelectionStart = oldText.Length;
308+
}
309+
310+
return;
311+
}
307312
}
308313

309314
var textArray = oldText.ToCharArray();
@@ -323,6 +328,9 @@ private static void Textbox_TextChanging(TextBox textbox, TextBoxTextChangingEve
323328
var displayText = textbox.GetValue(DefaultDisplayTextProperty) as string ?? string.Empty;
324329
if (string.IsNullOrEmpty(textbox.Text))
325330
{
331+
textbox.SetValue(OldTextProperty, displayText);
332+
textbox.SetValue(OldSelectionStartProperty, 0);
333+
textbox.SetValue(OldSelectionLengthProperty, 0);
326334
textbox.Text = displayText;
327335
return;
328336
}

0 commit comments

Comments
 (0)