Skip to content

Commit 73dc3d1

Browse files
author
Protik Biswas
committed
changing logic to avoid some difference between JS and Native layer event count
1 parent 6d1a24b commit 73dc3d1

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

vnext/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -546,17 +546,15 @@ void WindowsTextInputComponentView::HandleCommand(
546546

547547
winrt::Microsoft::ReactNative::ReadArgs(args.CommandArgs(), eventCount, text, begin, end);
548548

549-
// Standard synchronization check
549+
// Standard synchronization check - only accept current or future events
550550
bool isCurrentEvent = eventCount >= m_nativeEventCount;
551551

552-
// Special case: Allow setValue('') if it's responding to a recent onSubmitEditing event
552+
// Special case: Allow setValue('') if it's responding to the exact onSubmitEditing event
553553
// This is safe because clearing text doesn't depend on intermediate state
554554
bool isSubmitClearResponse = false;
555555
if (!isCurrentEvent && text.has_value() && winrt::to_string(text.value()).empty()) {
556-
// Check if this could be a response to a recent onSubmitEditing event
557-
// Only allow if the event is recent (within last 3 events) and we have clearTextOnSubmit behavior
558-
isSubmitClearResponse = (m_nativeEventCount - eventCount) <= 3 &&
559-
(m_clearTextOnSubmit || m_lastSubmitEventCount == eventCount);
556+
// Only allow if this is responding to the exact submit event we fired
557+
isSubmitClearResponse = (m_lastSubmitEventCount != -1 && eventCount == m_lastSubmitEventCount);
560558
}
561559

562560
if (isCurrentEvent || isSubmitClearResponse) {
@@ -578,6 +576,11 @@ void WindowsTextInputComponentView::HandleCommand(
578576
m_textServices->TxSendMessage(EM_SETSEL, static_cast<WPARAM>(begin), static_cast<LPARAM>(end), &res));
579577
}
580578

579+
// Clear the submit event count after using it to prevent reuse
580+
if (isSubmitClearResponse) {
581+
m_lastSubmitEventCount = -1;
582+
}
583+
581584
m_comingFromJS = false;
582585
}
583586
}

0 commit comments

Comments
 (0)