From 03040534e48151f463ce188bcb154de471658caa Mon Sep 17 00:00:00 2001 From: Eric Rozell Date: Fri, 12 Mar 2021 15:21:09 -0500 Subject: [PATCH 1/2] Change TextInput cursor behavior (#7285) * 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 * Change files --- ...ative-windows-b3c2f4a8-d704-4a38-b837-993459d15495.json | 7 +++++++ vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) 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" +} diff --git a/vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp b/vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp index 1b3da186385..8324c21d818 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 6482b1d9a6d94e2405f48ed5cd9cd8a74e15fb52 Mon Sep 17 00:00:00 2001 From: Igor Klemenski Date: Thu, 22 Apr 2021 18:20:14 -0700 Subject: [PATCH 2/2] Change files --- ...-native-windows-f478c436-a66f-4944-b578-80fea3b12488.json} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename change/{react-native-windows-b3c2f4a8-d704-4a38-b837-993459d15495.json => react-native-windows-f478c436-a66f-4944-b578-80fea3b12488.json} (59%) diff --git a/change/react-native-windows-b3c2f4a8-d704-4a38-b837-993459d15495.json b/change/react-native-windows-f478c436-a66f-4944-b578-80fea3b12488.json similarity index 59% rename from change/react-native-windows-b3c2f4a8-d704-4a38-b837-993459d15495.json rename to change/react-native-windows-f478c436-a66f-4944-b578-80fea3b12488.json index 724f9d5e816..ca76faf7040 100644 --- a/change/react-native-windows-b3c2f4a8-d704-4a38-b837-993459d15495.json +++ b/change/react-native-windows-f478c436-a66f-4944-b578-80fea3b12488.json @@ -1,6 +1,6 @@ { - "type": "prerelease", - "comment": "Change TextInput cursor behavior", + "type": "patch", + "comment": "Change TextInput cursor behavior (#7285)", "packageName": "react-native-windows", "email": "erozell@outlook.com", "dependentChangeType": "patch"