diff --git a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_static.cpp b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_static.cpp index 7e32e23dba790a6d5e22e3f46c19f7b08047432c..092a2936db035cfb01715c14db1458392d02c1df 100644 --- a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_static.cpp +++ b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_static.cpp @@ -182,4 +182,11 @@ void RichEditorModelStatic::BindSelectionMenu(FrameNode* frameNode, TextSpanType pattern->BindSelectionMenu(type, editorType, buildFunc, menuParam); } } +void RichEditorModelStatic::SetMaxLength(FrameNode* frameNode, const std::optional& maxLength) +{ + CHECK_NULL_VOID(frameNode); + auto pattern = frameNode->GetPattern(); + CHECK_NULL_VOID(pattern); + pattern->SetMaxLength(maxLength); +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_static.h b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_static.h index fa603854e60d698c94dca04f4a570312e7b98e42..ca42b11daf141cad6612718dc7345bbd933962e6 100644 --- a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_static.h +++ b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_static.h @@ -40,6 +40,7 @@ public: const std::optional& supportAvoidance); static void BindSelectionMenu(FrameNode* frameNode, TextSpanType& editorType, TextResponseType& type, std::function& buildFunc, SelectMenuParam& menuParam); + static void SetMaxLength(FrameNode* frameNode, const std::optional& maxLength); void SetDraggable(bool draggable); }; } // namespace OHOS::Ace::NG diff --git a/frameworks/core/interfaces/native/implementation/rich_editor_modifier.cpp b/frameworks/core/interfaces/native/implementation/rich_editor_modifier.cpp index 6995386eb37de3b1f4ff59ddfb0d2c121ffccb62..792ec6d7f8b8638700f252c20eb35cd4f37f33f0 100644 --- a/frameworks/core/interfaces/native/implementation/rich_editor_modifier.cpp +++ b/frameworks/core/interfaces/native/implementation/rich_editor_modifier.cpp @@ -28,6 +28,7 @@ #include "core/interfaces/native/generated/interface/node_api.h" #include "rich_editor_controller_peer_impl.h" #include "rich_editor_styled_string_controller_peer_impl.h" +#include "core/interfaces/native/utility/validators.h" namespace OHOS::Ace::NG::Converter { namespace { @@ -639,9 +640,9 @@ void MaxLengthImpl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto convValue = value ? Converter::OptConvert(*value) : std::nullopt; - auto validValue = convValue && convValue.value() >= 0 ? convValue : std::nullopt; - RichEditorModelNG::SetMaxLength(frameNode, validValue); + auto convValue = Converter::OptConvertPtr(value); + Validator::ValidateNonNegative(convValue); + RichEditorModelStatic::SetMaxLength(frameNode, convValue); } void MaxLinesImpl(Ark_NativePointer node, const Opt_Number* value)