diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp index 69c967b8cd452fe6b2216965b599260a39373792..eda3793984386178fd4f9193b57b84e63f0169c0 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp +++ b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp @@ -1289,10 +1289,14 @@ void TextFieldPattern::FireEventHubOnChange(const std::string& text) void TextFieldPattern::HandleTouchEvent(const TouchEventInfo& info) { + auto touchType = info.GetTouches().front().GetTouchType(); + if (touchType == TouchType::UP) { + RequestKeyboardAfterLongPress(); + } if (SelectOverlayIsOn() && !isTouchCaret_) { return; } - auto touchType = info.GetTouches().front().GetTouchType(); + if (touchType == TouchType::DOWN) { HandleTouchDown(info.GetTouches().front().GetLocalLocation()); } else if (touchType == TouchType::UP) { @@ -1356,14 +1360,6 @@ void TextFieldPattern::HandleTouchUp() } } } -#if defined(OHOS_STANDARD_SYSTEM) && !defined(PREVIEW) - if (isLongPress_ && !imeShown_ && !isCustomKeyboardAttached_ && HasFocus()) { - if (RequestKeyboard(false, true, true)) { - NotifyOnEditChanged(true); - } - } - isLongPress_ = false; -#endif } void TextFieldPattern::HandleTouchMove(const TouchEventInfo& info) @@ -2385,8 +2381,6 @@ bool TextFieldPattern::OnPreShowSelectOverlay( isSupportCameraInput_ = false; #endif overlayInfo.menuInfo.showCameraInput = !IsSelected() && isSupportCameraInput_ && !customKeyboardBuilder_; - auto gesture = host->GetOrCreateGestureEventHub(); - gesture->RemoveTouchEvent(GetTouchListener()); return true; } @@ -6232,4 +6226,14 @@ void TextFieldPattern::HandleOnDragStatusCallback( break; } } + +void TextFieldPattern::RequestKeyboardAfterLongPress() +{ +#if defined(OHOS_STANDARD_SYSTEM) && !defined(PREVIEW) + if (isLongPress_ && HasFocus() && RequestKeyboard(false, true, true)) { + NotifyOnEditChanged(true); + } + isLongPress_ = false; +#endif +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h index 72e7ef59e8699d9c8552a6bdb839347e10a0aeb1..476fdb82e4636a8f3fbe730e71f387d1bb6750b3 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h +++ b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h @@ -1229,6 +1229,7 @@ private: void ScrollToSafeArea() const override; void RecordSubmitEvent() const; void UpdateCancelNode(); + void RequestKeyboardAfterLongPress(); RectF frameRect_; RectF contentRect_;