Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Fix cursor resetting in TextInput.",
"packageName": "react-native-windows",
"email": "igklemen@microsoft.com",
"dependentChangeType": "patch"
}
7 changes: 7 additions & 0 deletions vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,10 +612,17 @@ 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<uint32_t>(oldCursor) <= newValue.size()) {
textBox.SelectionStart(oldCursor);
} else {
textBox.SelectionStart(newValue.size());
}
}
} else if (text.IsNull())
textBox.ClearValue(xaml::Controls::TextBox::TextProperty());
Expand Down