cj_frontend RichEditor component support onDidChange callback

Signed-off-by: yuzhuohao <1171326722@qq.com>
This commit is contained in:
yuzhuohao 2024-07-02 17:48:55 +08:00
parent 28262da379
commit 5e4462f2e6
4 changed files with 22 additions and 1 deletions

View File

@ -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::*;

View File

@ -243,4 +243,17 @@ void FfiOHOSAceFrameworkRichEditorPreventDefault(int64_t id)
auto nativePasteEvent = FFIData::GetData<NativePasteEvent>(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));
}
}

View File

@ -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

View File

@ -217,7 +217,7 @@ private:
std::list<RichEditorAbstractSpanResult> richEditorDeleteSpans_;
};
class RichEditorChangeValue : public BaseEventInfo {
class ACE_FORCE_EXPORT RichEditorChangeValue : public BaseEventInfo {
DECLARE_ACE_TYPE(RichEditorChangeValue, BaseEventInfo)
public:
RichEditorChangeValue() : BaseEventInfo("RichEditorChangeValue") {}