From 5e4462f2e6a6cc8f5cf935192fe5df30d8a16701 Mon Sep 17 00:00:00 2001 From: yuzhuohao <1171326722@qq.com> Date: Tue, 2 Jul 2024 17:48:55 +0800 Subject: [PATCH] cj_frontend RichEditor component support onDidChange callback Signed-off-by: yuzhuohao <1171326722@qq.com> --- build/libace.map | 1 + .../interfaces/cj_ffi/cj_richeditor_ffi.cpp | 13 +++++++++++++ .../interfaces/cj_ffi/cj_richeditor_ffi.h | 7 +++++++ .../pattern/rich_editor/rich_editor_event_hub.h | 2 +- 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/build/libace.map b/build/libace.map index 84e569aedf9..f550138a8b0 100644 --- a/build/libace.map +++ b/build/libace.map @@ -237,6 +237,7 @@ OHOS::Ace::NG::RichEditorAbstractSpanResult::*; OHOS::Ace::NG::RichEditorInsertValue::*; OHOS::Ace::NG::RichEditorDeleteValue::*; + OHOS::Ace::NG::RichEditorChangeValue::*; OHOS::Ace::TabController::*; OHOS::Ace::ParseFontFeatureSettings*; OHOS::Ace::StorageProxy::*; diff --git a/frameworks/bridge/cj_frontend/interfaces/cj_ffi/cj_richeditor_ffi.cpp b/frameworks/bridge/cj_frontend/interfaces/cj_ffi/cj_richeditor_ffi.cpp index 86938216362..f333d10504d 100644 --- a/frameworks/bridge/cj_frontend/interfaces/cj_ffi/cj_richeditor_ffi.cpp +++ b/frameworks/bridge/cj_frontend/interfaces/cj_ffi/cj_richeditor_ffi.cpp @@ -243,4 +243,17 @@ void FfiOHOSAceFrameworkRichEditorPreventDefault(int64_t id) auto nativePasteEvent = FFIData::GetData(id); nativePasteEvent->PreventDefault(); } + +void FfiOHOSAceFrameworkRichEditorOnDidChange(void(*callback)(CJTextRange rangeBefore, CJTextRange rangeAfter)) +{ + auto onDidChange = [cjCallback = CJLambda::Create(callback)](const NG::RichEditorChangeValue& changeValue) { + const auto& rangeBefore = changeValue.GetRangeBefore(); + const auto& rangeAfter = changeValue.GetRangeAfter(); + CJTextRange cjRangeBefore = { rangeBefore.start, rangeBefore.end }; + CJTextRange cjRangeAfter = { rangeAfter.start, rangeAfter.end }; + + cjCallback(cjRangeBefore, cjRangeAfter); + }; + RichEditorModel::GetInstance()->SetOnDidChange(std::move(onDidChange)); +} } diff --git a/frameworks/bridge/cj_frontend/interfaces/cj_ffi/cj_richeditor_ffi.h b/frameworks/bridge/cj_frontend/interfaces/cj_ffi/cj_richeditor_ffi.h index 7c26c088d54..882f19bd754 100644 --- a/frameworks/bridge/cj_frontend/interfaces/cj_ffi/cj_richeditor_ffi.h +++ b/frameworks/bridge/cj_frontend/interfaces/cj_ffi/cj_richeditor_ffi.h @@ -28,6 +28,11 @@ struct NativeRichEditorInsertValue { const char* insertValue; }; +struct CJTextRange { + int32_t start; + int32_t end; +}; + class ACE_EXPORT NativePasteEvent : public OHOS::FFI::FFIData { DECL_TYPE(NativeTextCommonEvent, OHOS::FFI::FFIData) public: @@ -62,6 +67,8 @@ CJ_EXPORT void FfiOHOSAceFrameworkRichEditorOnSelect(void(*callback)(NativeRichE CJ_EXPORT void FfiOHOSAceFrameworkRichEditorAboutToDelete(bool(*callback)(NativeRichEditorDeleteValue)); CJ_EXPORT void FfiOHOSAceFrameworkRichEditorOnPaste(void(*callback)(int64_t)); CJ_EXPORT void FfiOHOSAceFrameworkRichEditorPreventDefault(int64_t controller); +CJ_EXPORT void FfiOHOSAceFrameworkRichEditorOnDidChange( + void(*callback)(CJTextRange rangeBefore, CJTextRange rangeAfter)); } #endif // OHOS_ACE_FRAMEWORK_CJ_RICHEDITOR_FFI_H diff --git a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_event_hub.h b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_event_hub.h index fe13c94233e..2ec3e27bac3 100644 --- a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_event_hub.h +++ b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_event_hub.h @@ -217,7 +217,7 @@ private: std::list richEditorDeleteSpans_; }; -class RichEditorChangeValue : public BaseEventInfo { +class ACE_FORCE_EXPORT RichEditorChangeValue : public BaseEventInfo { DECLARE_ACE_TYPE(RichEditorChangeValue, BaseEventInfo) public: RichEditorChangeValue() : BaseEventInfo("RichEditorChangeValue") {}