Skip to content

Commit 96e9efa

Browse files
iamAbhi-916Abhijeet Jha
andauthored
Textinput double clicking selects text (#14515)
* added check for double click on textInput component view connecting it to WM_LBUTTONDBLCLK * Change files * updated for lint fix * updated to remove position( Distance check) --------- Co-authored-by: Abhijeet Jha <abhijeetjha@microsoft.com>
1 parent 50497af commit 96e9efa

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "none",
3+
"comment": "added check for double click on textInput component view connecting it to WM_LBUTTONDBLCLK",
4+
"packageName": "react-native-windows",
5+
"email": "email not defined",
6+
"dependentChangeType": "none"
7+
}

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,19 @@ WPARAM PointerRoutedEventArgsToMouseWParam(
621621
return wParam;
622622
}
623623

624+
bool WindowsTextInputComponentView::IsDoubleClick() {
625+
using namespace std::chrono;
626+
627+
auto now = steady_clock::now();
628+
auto duration = duration_cast<milliseconds>(now - m_lastClickTime).count();
629+
630+
const int DOUBLE_CLICK_TIME_MS = ::GetDoubleClickTime();
631+
632+
m_lastClickTime = now;
633+
634+
return (duration < DOUBLE_CLICK_TIME_MS);
635+
}
636+
624637
void WindowsTextInputComponentView::OnPointerPressed(
625638
const winrt::Microsoft::ReactNative::Composition::Input::PointerRoutedEventArgs &args) noexcept {
626639
UINT msg = 0;
@@ -637,7 +650,11 @@ void WindowsTextInputComponentView::OnPointerPressed(
637650
if (pp.PointerDeviceType() == winrt::Microsoft::ReactNative::Composition::Input::PointerDeviceType::Mouse) {
638651
switch (pp.Properties().PointerUpdateKind()) {
639652
case winrt::Microsoft::ReactNative::Composition::Input::PointerUpdateKind::LeftButtonPressed:
640-
msg = WM_LBUTTONDOWN;
653+
if (IsDoubleClick()) {
654+
msg = WM_LBUTTONDBLCLK;
655+
} else {
656+
msg = WM_LBUTTONDOWN;
657+
}
641658
break;
642659
case winrt::Microsoft::ReactNative::Composition::Input::PointerUpdateKind::MiddleButtonPressed:
643660
msg = WM_MBUTTONDOWN;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ struct WindowsTextInputComponentView
7070
std::optional<std::string> getAccessiblityValue() noexcept override;
7171
void setAcccessiblityValue(std::string &&value) noexcept override;
7272
bool getAcccessiblityIsReadOnly() noexcept override;
73+
bool IsDoubleClick();
7374

7475
WindowsTextInputComponentView(
7576
const winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compContext,
@@ -140,6 +141,7 @@ struct WindowsTextInputComponentView
140141
DWORD m_propBitsMask{0};
141142
DWORD m_propBits{0};
142143
HCURSOR m_hcursor{nullptr};
144+
std::chrono::steady_clock::time_point m_lastClickTime{};
143145
std::vector<facebook::react::CompWindowsTextInputSubmitKeyEventsStruct> m_submitKeyEvents;
144146
};
145147

0 commit comments

Comments
 (0)