Skip to content

Commit

Permalink
fix(textbox): multiline paste didn't move the selection to the end of…
Browse files Browse the repository at this point in the history
… the paste text
  • Loading branch information
ramezgerges committed Jun 3, 2024
1 parent d26f1cc commit 601d59b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
12 changes: 12 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,19 @@ internal string ProcessTextInput(string newText)
try
{
_isInputModifyingText = true;
var oldText = Text;
Text = newText;

#if __SKIA__
if (_pendingSelection is { } selection && Text == oldText)
{
// OnTextChanged won't fire, so we immediately change the selection.
// Note how we check that Text (after assignment) == oldText and
// not oldText == newText. This is because CoerceText can make it so that
// newText != oldText but Text (after assignment) == oldText
SelectInternal(selection.start, selection.length);
}
#endif
}
finally
{
Expand Down
28 changes: 5 additions & 23 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -508,20 +508,10 @@ partial void OnKeyDownPartial(KeyRoutedEventArgs args)
var caretXOffset = _caretXOffset;

_suppressCurrentlyTyping = true;
if (text == Text)
{
if (!_isPressed)
{
SelectInternal(selectionStart, selectionLength);
}
}
else
{
_clearHistoryOnTextChanged = false;
_pendingSelection = (selectionStart, selectionLength);
ProcessTextInput(text);
_clearHistoryOnTextChanged = true;
}
_clearHistoryOnTextChanged = false;
_pendingSelection = (selectionStart, selectionLength);
ProcessTextInput(text);
_clearHistoryOnTextChanged = true;
_suppressCurrentlyTyping = false;

// don't change the caret offset when moving up and down
Expand Down Expand Up @@ -1254,15 +1244,7 @@ partial void PasteFromClipboardPartial(string clipboardText, int selectionStart,
CommitAction(new ReplaceAction(Text, newText, selectionStart));
}

if (Text == newText)
{
// OnTextChanged won't fire, so we immediately change the selection
Select(selectionStart + clipboardText.Length, 0);
}
else
{
_pendingSelection = (selectionStart + clipboardText.Length, 0);
}
_pendingSelection = (selectionStart + clipboardText.Length, 0);
}
}

Expand Down

0 comments on commit 601d59b

Please sign in to comment.