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 295409ed583ea60e5b5a575a5ae4f636b059b7f0..5901e7bc88287c72dc24a50dd10438feb0911e8b 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 @@ -402,10 +402,6 @@ bool TextFieldPattern::OnDirtyLayoutWrapperSwap(const RefPtr& dir inlineSelectAllFlag_ = false; showSelect_ = true; } - if (needSelectAll_ && !isLongPress_) { - HandleOnSelectAll(true); - needSelectAll_ = false; - } if (mouseStatus_ == MouseStatus::RELEASED) { mouseStatus_ = MouseStatus::NONE; } @@ -654,10 +650,6 @@ void TextFieldPattern::HandleFocusEvent() CHECK_NULL_VOID(paintProperty); auto layoutProperty = GetLayoutProperty(); CHECK_NULL_VOID(layoutProperty); - auto isSelectAll = layoutProperty->GetSelectAllValueValue(false); - if (isSelectAll && !contentController_->IsEmpty()) { - needSelectAll_ = true; - } if (IsNormalInlineState()) { ApplyInlineStates(true); inlineFocusState_ = true; @@ -1687,6 +1679,7 @@ void TextFieldPattern::HandleSingleClickEvent(GestureEvent& info) SetIsSingleHandle(true); CloseSelectOverlay(true); + auto isSelectAll = layoutProperty->GetSelectAllValueValue(false); if (RepeatClickCaret(info.GetLocalLocation(), lastCaretIndex) && info.GetSourceDevice() != SourceType::MOUSE) { if (contentController_->IsEmpty()) { ProcessOverlay(true, true, true, true); @@ -1697,7 +1690,8 @@ void TextFieldPattern::HandleSingleClickEvent(GestureEvent& info) && !IsNormalInlineState()) { if (GetNakedCharPosition() >= 0) { DelayProcessOverlay(true, true, false); - } else if (needSelectAll_) { + } else if (isSelectAll && !contentController_->IsEmpty() && isFocusedBeforeClick_) { + isFocusedBeforeClick_ = false; HandleOnSelectAll(true); } else { ProcessOverlay(true, true, false); @@ -1709,6 +1703,10 @@ void TextFieldPattern::HandleSingleClickEvent(GestureEvent& info) } // emulate clicking bottom of the textField UpdateTextFieldManager(Offset(parentGlobalOffset_.GetX(), parentGlobalOffset_.GetY()), frameRect_.Height()); + if (isSelectAll && !contentController_->IsEmpty() && isFocusedBeforeClick_) { + isFocusedBeforeClick_ = false; + HandleOnSelectAll(true); + } host->MarkDirtyNode(PROPERTY_UPDATE_RENDER); } @@ -1762,10 +1760,6 @@ bool TextFieldPattern::ProcessAutoFill() void TextFieldPattern::HandleDoubleClickEvent(GestureEvent& info) { - if (showSelect_) { - SetIsSingleHandle(true); - CloseSelectOverlay(); - } selectController_->UpdateSelectByOffset(info.GetLocalLocation()); if (IsSelected()) { StopTwinkling(); @@ -2224,6 +2218,7 @@ void TextFieldPattern::HandleLongPress(GestureEvent& info) ProcessOverlay(true, true); UpdateSelectMenuVisibility(true); } + isFocusedBeforeClick_ = false; host->MarkDirtyNode(PROPERTY_UPDATE_RENDER); } @@ -2569,9 +2564,6 @@ void TextFieldPattern::OnHandleClosed(bool closedByGlobalEvent) UpdateSelectMenuVisibility(false); } UpdateShowMagnifier(); - auto tmpHost = GetHost(); - CHECK_NULL_VOID(tmpHost); - tmpHost->MarkDirtyNode(PROPERTY_UPDATE_RENDER); } void TextFieldPattern::InitEditingValueText(std::string content) 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 978704f9005d4c76386ff6b314eaf67df8d05f16..1724bc0656d5f3f06287b0134c9369f52e944735 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 @@ -1366,7 +1366,6 @@ private: bool isShowMagnifier_ = false; OffsetF localOffset_; bool isTouchCaret_ = false; - bool needSelectAll_ = false; }; } // namespace OHOS::Ace::NG