From f55da04c28296f3feece429b7e31d8ba2749a39e Mon Sep 17 00:00:00 2001 From: Eric Rozell Date: Thu, 4 Mar 2021 20:42:44 -0500 Subject: [PATCH 1/2] Change TextInput cursor behavior As stated in issue #7283, the cursor position changes seem to be somewhat different on each platform. Since we're already adding code in react-native-windows to change the Windows default cursor positioning behavior, we might as well make it a bit more consistent with other platforms. The change here matches the behavior on iOS, macOS and Web (so it's only different from Android, which seems to keep cursor position relative to the TextInput value length constant). Fixes #7283 --- vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp b/vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp index 861816dbc72..8888e77e6bf 100644 --- a/vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp +++ b/vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp @@ -618,7 +618,7 @@ void TextInputShadowNode::SetText(const winrt::Microsoft::ReactNative::JSValue & auto newValue = react::uwp::asHstring(text); if (oldValue != newValue) { textBox.Text(newValue); - if (static_cast(oldCursor) <= newValue.size()) { + if (oldValue.size() == newValue.size()) { textBox.SelectionStart(oldCursor); } else { textBox.SelectionStart(newValue.size()); From ca7fb419fdf21a8957d98b62bef7455fe6bbbe58 Mon Sep 17 00:00:00 2001 From: Eric Rozell Date: Thu, 4 Mar 2021 20:47:09 -0500 Subject: [PATCH 2/2] Change files --- ...ative-windows-b3c2f4a8-d704-4a38-b837-993459d15495.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/react-native-windows-b3c2f4a8-d704-4a38-b837-993459d15495.json diff --git a/change/react-native-windows-b3c2f4a8-d704-4a38-b837-993459d15495.json b/change/react-native-windows-b3c2f4a8-d704-4a38-b837-993459d15495.json new file mode 100644 index 00000000000..724f9d5e816 --- /dev/null +++ b/change/react-native-windows-b3c2f4a8-d704-4a38-b837-993459d15495.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Change TextInput cursor behavior", + "packageName": "react-native-windows", + "email": "erozell@outlook.com", + "dependentChangeType": "patch" +}