Skip to content

Commit

Permalink
fix(TextInput): Ensure cursor stays at end of TextInput (#1531)
Browse files Browse the repository at this point in the history
When `value` or `defaultValue` is set on the TextInput, if the cursor started at the end, it should remain at the end after the text is updated.

Towards #1109
  • Loading branch information
rozele authored Nov 17, 2017
1 parent 7bdf9f9 commit 7251e03
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions ReactWindows/ReactNative/Views/TextInput/ReactTextInputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -512,15 +512,22 @@ public override void UpdateExtraData(ReactTextBox view, object extraData)
}

var text = textUpdate.Item2;
var previousText = view.Text;
var selectionStart = view.SelectionStart;
var selectionLength = view.SelectionLength;
var textLength = text?.Length ?? 0;
var maxLength = textLength - selectionLength;

view.Text = text ?? "";

view.SelectionStart = Math.Min(selectionStart, textLength);
view.SelectionLength = Math.Min(selectionLength, maxLength < 0 ? 0 : maxLength);
if (selectionStart == previousText.Length)
{
view.SelectionStart = textLength;
}
else
{
view.SelectionStart = Math.Min(selectionStart, textLength);
view.SelectionLength = Math.Min(selectionLength, maxLength < 0 ? 0 : maxLength);
}

if (removeOnSelectionChange)
{
Expand Down

0 comments on commit 7251e03

Please sign in to comment.