From b8d65efd186e413e154d15e8b65a38514e14b619 Mon Sep 17 00:00:00 2001 From: Igor Klemenski Date: Fri, 5 Feb 2021 15:03:21 -0800 Subject: [PATCH 1/3] Fix cursor resetting in TextInput. --- .../Microsoft.ReactNative/Views/TextInputViewManager.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp b/vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp index 392325a9351..79553e2b90a 100644 --- a/vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp +++ b/vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp @@ -612,10 +612,18 @@ void TextInputShadowNode::SetText(const winrt::Microsoft::ReactNative::JSValue & if (m_mostRecentEventCount == m_nativeEventCount) { if (textBox) { if (text.Type() == winrt::Microsoft::ReactNative::JSValueType::String) { + auto oldCursor = textBox.SelectionStart(); + auto oldSelectionLength = textBox.SelectionLength(); auto oldValue = textBox.Text(); auto newValue = react::uwp::asHstring(text); if (oldValue != newValue) { textBox.Text(newValue); + if (static_cast(oldCursor) <= newValue.size()) { + textBox.SelectionStart(oldCursor); + } else { + textBox.SelectionStart(newValue.size()); + } + textBox.SelectionLength(oldSelectionLength); } } else if (text.IsNull()) textBox.ClearValue(xaml::Controls::TextBox::TextProperty()); From 6880ec2c0f5b35ed437d4b790976301d3cc8dd5b Mon Sep 17 00:00:00 2001 From: Igor Klemenski Date: Fri, 5 Feb 2021 15:07:24 -0800 Subject: [PATCH 2/3] Change files --- ...ative-windows-2dead2dd-8acc-4a17-a3f2-7e3091cde5ad.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/react-native-windows-2dead2dd-8acc-4a17-a3f2-7e3091cde5ad.json diff --git a/change/react-native-windows-2dead2dd-8acc-4a17-a3f2-7e3091cde5ad.json b/change/react-native-windows-2dead2dd-8acc-4a17-a3f2-7e3091cde5ad.json new file mode 100644 index 00000000000..210db58a4cf --- /dev/null +++ b/change/react-native-windows-2dead2dd-8acc-4a17-a3f2-7e3091cde5ad.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Fix cursor resetting in TextInput.", + "packageName": "react-native-windows", + "email": "igklemen@microsoft.com", + "dependentChangeType": "patch" +} From 5e2c5c234b1632d11fd59624ac0e2bcec0c28f42 Mon Sep 17 00:00:00 2001 From: Igor Klemenski Date: Mon, 8 Feb 2021 13:39:28 -0800 Subject: [PATCH 3/3] Do no preserve selection, just cursor. --- vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp b/vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp index 79553e2b90a..7f3c7b0455a 100644 --- a/vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp +++ b/vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp @@ -623,7 +623,6 @@ void TextInputShadowNode::SetText(const winrt::Microsoft::ReactNative::JSValue & } else { textBox.SelectionStart(newValue.size()); } - textBox.SelectionLength(oldSelectionLength); } } else if (text.IsNull()) textBox.ClearValue(xaml::Controls::TextBox::TextProperty());