Skip to content

Commit

Permalink
fix(textbox): BeforeTextChanging crashing ing in specific cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ramezgerges committed Oct 8, 2024
1 parent 3312489 commit 819ccc2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,21 @@ private object CoerceText(object baseValue)
BeforeTextChanging?.Invoke(this, args);
if (args.Cancel)
{
#if __SKIA__
if (_isSkiaTextBox)
{
// On WinUI, when a selection is canceled, the TextBox invokes a bunch of weird
// SelectionChanging events followed by a bunch of matching SelectionChanged.
// Probing for the value of SelectionStart and SelectionLength during these SelectionChanging
// events will give incorrect transient values and the SelectionChanged events will end up
// with the selection where it started (before the text change). Also, the direction of
// of the selection will be reset, i.e. if the selection end was "at the start", then it won't be
// so anymore.
// In Uno, we choose a simpler sequence. We just reset the selection direction (like WinUI) and
// we don't invoke any selection change events (since selection was in fact not changed).
_pendingSelection = (SelectionStart, SelectionLength);
}
#endif
return DependencyProperty.UnsetValue;
}

Expand Down
1 change: 0 additions & 1 deletion src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ private void TrySetCurrentlyTyping(bool newValue)
}
else
{
global::System.Diagnostics.CI.Assert(!_isSkiaTextBox || _selection.length == 0);
_historyIndex++;
_history.RemoveAllAt(_historyIndex);
_history.Add(new HistoryRecord(
Expand Down

0 comments on commit 819ccc2

Please sign in to comment.