Skip to content

Commit 62ec382

Browse files
iamAbhi-916Abhijeet Jha
authored andcommitted
Textinput double clicking selects text (microsoft#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 <[email protected]>
1 parent 062165f commit 62ec382

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
@@ -631,6 +631,19 @@ WPARAM PointerRoutedEventArgsToMouseWParam(
631631
return wParam;
632632
}
633633

634+
bool WindowsTextInputComponentView::IsDoubleClick() {
635+
using namespace std::chrono;
636+
637+
auto now = steady_clock::now();
638+
auto duration = duration_cast<milliseconds>(now - m_lastClickTime).count();
639+
640+
const int DOUBLE_CLICK_TIME_MS = ::GetDoubleClickTime();
641+
642+
m_lastClickTime = now;
643+
644+
return (duration < DOUBLE_CLICK_TIME_MS);
645+
}
646+
634647
void WindowsTextInputComponentView::OnPointerPressed(
635648
const winrt::Microsoft::ReactNative::Composition::Input::PointerRoutedEventArgs &args) noexcept {
636649
UINT msg = 0;
@@ -647,7 +660,11 @@ void WindowsTextInputComponentView::OnPointerPressed(
647660
if (pp.PointerDeviceType() == winrt::Microsoft::ReactNative::Composition::Input::PointerDeviceType::Mouse) {
648661
switch (pp.Properties().PointerUpdateKind()) {
649662
case winrt::Microsoft::ReactNative::Composition::Input::PointerUpdateKind::LeftButtonPressed:
650-
msg = WM_LBUTTONDOWN;
663+
if (IsDoubleClick()) {
664+
msg = WM_LBUTTONDBLCLK;
665+
} else {
666+
msg = WM_LBUTTONDOWN;
667+
}
651668
break;
652669
case winrt::Microsoft::ReactNative::Composition::Input::PointerUpdateKind::MiddleButtonPressed:
653670
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,
@@ -141,6 +142,7 @@ struct WindowsTextInputComponentView
141142
DWORD m_propBitsMask{0};
142143
DWORD m_propBits{0};
143144
HCURSOR m_hcursor{nullptr};
145+
std::chrono::steady_clock::time_point m_lastClickTime{};
144146
std::vector<facebook::react::CompWindowsTextInputSubmitKeyEventsStruct> m_submitKeyEvents;
145147
};
146148

0 commit comments

Comments
 (0)