From 170ba55dc06c54e288aa9023d04b6dfb1ea26372 Mon Sep 17 00:00:00 2001 From: Zhang Jinyu Date: Tue, 18 Jun 2024 15:50:20 +0800 Subject: [PATCH] richEditor_OnPaste_OnCut_OnCopy_modifier Signed-off-by: Zhang Jinyu Change-Id: If2c1555fca558d4d0275fca9d9cbd0fcda8827d4 --- .../ark_component/src/ArkRichEditor.ts | 55 +++++++- .../engine/arkComponent.js | 53 +++++++- .../arkts_native_api_impl_bridge.cpp | 12 ++ .../arkts_native_rich_editor_bridge.cpp | 124 ++++++++++++++++++ .../arkts_native_rich_editor_bridge.h | 11 +- .../rich_editor/rich_editor_model_ng.cpp | 24 ++++ .../rich_editor/rich_editor_model_ng.h | 3 + .../core/interfaces/arkoala/arkoala_api.h | 6 + .../native/node/rich_editor_modifier.cpp | 62 ++++++++- 9 files changed, 344 insertions(+), 6 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkRichEditor.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkRichEditor.ts index 9ede5b8c8f4..10e4f1fda50 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkRichEditor.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkRichEditor.ts @@ -124,6 +124,48 @@ class RichEditorOnEditingChangeModifier extends ModifierWithKey<(value: boolean) } } +class RichEditorOnPasteModifier extends ModifierWithKey<(event?: PasteEvent) => void> { + constructor(value: (event?: PasteEvent) => void) { + super(value); + } + static identity = Symbol('richEditorOnPaste'); + applyPeer(node: KNode, reset: boolean): void { + if (reset) { + getUINativeModule().richEditor.resetOnPaste(node); + } else { + getUINativeModule().richEditor.setOnPaste(node, this.value); + } + } +} + +class RichEditorOnCutModifier extends ModifierWithKey> { + constructor(value: Callback) { + super(value); + } + static identity = Symbol('richEditorOnCut'); + applyPeer(node: KNode, reset: boolean): void { + if (reset) { + getUINativeModule().richEditor.resetOnCut(node); + } else { + getUINativeModule().richEditor.setOnCut(node, this.value); + } + } +} + +class RichEditorOnCopyModifier extends ModifierWithKey> { + constructor(value: Callback) { + super(value); + } + static identity = Symbol('richEditorOnCopy'); + applyPeer(node: KNode, reset: boolean): void { + if (reset) { + getUINativeModule().richEditor.resetOnCopy(node); + } else { + getUINativeModule().richEditor.setOnCopy(node, this.value); + } + } +} + class RichEditorEnterKeyTypeModifier extends ModifierWithKey { constructor(value: EnterKeyType) { super(value); @@ -170,8 +212,10 @@ class ArkRichEditorComponent extends ArkComponent implements CommonMethod void): RichEditorAttribute { - throw new Error('Method not implemented.'); + modifierWithKey(this._modifiersWithKeys, RichEditorOnPasteModifier.identity, RichEditorOnPasteModifier, callback); + return this; } + onReady(callback: () => void): RichEditorAttribute { modifierWithKey(this._modifiersWithKeys, RichEditorOnReadyModifier.identity, RichEditorOnReadyModifier, callback); return this; @@ -202,11 +246,18 @@ class ArkRichEditorComponent extends ArkComponent implements CommonMethod): RichEditorAttribute { + modifierWithKey(this._modifiersWithKeys, RichEditorOnCutModifier.identity, RichEditorOnCutModifier, callback); + return this; + } + onCopy(callback: Callback): RichEditorAttribute { + modifierWithKey(this._modifiersWithKeys, RichEditorOnCopyModifier.identity, RichEditorOnCopyModifier, callback); + return this; + } enterKeyType(value: EnterKeyType): RichEditorAttribute { modifierWithKey(this._modifiersWithKeys, RichEditorEnterKeyTypeModifier.identity, RichEditorEnterKeyTypeModifier, value); return this; } - } // @ts-ignore diff --git a/frameworks/bridge/declarative_frontend/engine/arkComponent.js b/frameworks/bridge/declarative_frontend/engine/arkComponent.js index 600682c4f17..fb767f94db0 100644 --- a/frameworks/bridge/declarative_frontend/engine/arkComponent.js +++ b/frameworks/bridge/declarative_frontend/engine/arkComponent.js @@ -7437,6 +7437,48 @@ class RichEditorOnEditingChangeModifier extends ModifierWithKey { } RichEditorOnEditingChangeModifier.identity = Symbol('richEditorOnEditingChange'); +class RichEditorOnPasteModifier extends ModifierWithKey { + constructor(value) { + super(value); + } + applyPeer(node, reset) { + if (reset) { + getUINativeModule().richEditor.resetOnPaste(node); + } else { + getUINativeModule().richEditor.setOnPaste(node, this.value); + } + } +} +RichEditorOnPasteModifier.identity = Symbol('richEditorOnPaste'); + +class RichEditorOnCutModifier extends ModifierWithKey { + constructor(value) { + super(value); + } + applyPeer(node, reset) { + if (reset) { + getUINativeModule().richEditor.resetOnCut(node); + } else { + getUINativeModule().richEditor.setOnCut(node, this.value); + } + } +} +RichEditorOnCutModifier.identity = Symbol('richEditorOnCut'); + +class RichEditorOnCopyModifier extends ModifierWithKey { + constructor(value) { + super(value); + } + applyPeer(node, reset) { + if (reset) { + getUINativeModule().richEditor.resetOnCopy(node); + } else { + getUINativeModule().richEditor.setOnCopy(node, this.value); + } + } +} +RichEditorOnCopyModifier.identity = Symbol('richEditorOnCopy'); + class RichEditorEnterKeyTypeModifier extends ModifierWithKey { constructor(value) { super(value); @@ -7487,7 +7529,8 @@ class ArkRichEditorComponent extends ArkComponent { } onPaste(callback) { - throw new Error('Method not implemented.'); + modifierWithKey(this._modifiersWithKeys, RichEditorOnPasteModifier.identity, RichEditorOnPasteModifier, callback); + return this; } onReady(callback) { modifierWithKey(this._modifiersWithKeys, RichEditorOnReadyModifier.identity, RichEditorOnReadyModifier, callback); @@ -7519,6 +7562,14 @@ class ArkRichEditorComponent extends ArkComponent { modifierWithKey(this._modifiersWithKeys, RichEditorOnEditingChangeModifier.identity, RichEditorOnEditingChangeModifier, callback); return this; } + onCut(callback) { + modifierWithKey(this._modifiersWithKeys, RichEditorOnCutModifier.identity, RichEditorOnCutModifier, callback); + return this; + } + onCopy(callback) { + modifierWithKey(this._modifiersWithKeys, RichEditorOnCopyModifier.identity, RichEditorOnCopyModifier, callback); + return this; + } } // @ts-ignore if (globalThis.RichEditor !== undefined) { diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_api_impl_bridge.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_api_impl_bridge.cpp index a20dc9c1e80..1840c24f70a 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_api_impl_bridge.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_api_impl_bridge.cpp @@ -1594,6 +1594,18 @@ ArkUINativeModuleValue ArkUINativeModule::GetArkUINativeModule(ArkUIRuntimeCallI panda::FunctionRef::New(const_cast(vm), RichEditorBridge::SetOnEditingChange)); richEditor->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetOnEditingChange"), panda::FunctionRef::New(const_cast(vm), RichEditorBridge::ResetOnEditingChange)); + richEditor->Set(vm, panda::StringRef::NewFromUtf8(vm, "setOnPaste"), + panda::FunctionRef::New(const_cast(vm), RichEditorBridge::SetOnPaste)); + richEditor->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetOnPaste"), + panda::FunctionRef::New(const_cast(vm), RichEditorBridge::ResetOnPaste)); + richEditor->Set(vm, panda::StringRef::NewFromUtf8(vm, "setOnCut"), + panda::FunctionRef::New(const_cast(vm), RichEditorBridge::SetOnCut)); + richEditor->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetOnCut"), + panda::FunctionRef::New(const_cast(vm), RichEditorBridge::ResetOnCut)); + richEditor->Set(vm, panda::StringRef::NewFromUtf8(vm, "setOnCopy"), + panda::FunctionRef::New(const_cast(vm), RichEditorBridge::SetOnCopy)); + richEditor->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetOnCopy"), + panda::FunctionRef::New(const_cast(vm), RichEditorBridge::ResetOnCopy)); object->Set(vm, panda::StringRef::NewFromUtf8(vm, "richEditor"), richEditor); auto textArea = panda::ObjectRef::New(vm); diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_rich_editor_bridge.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_rich_editor_bridge.cpp index 82723abbab8..c68c6e30ad0 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_rich_editor_bridge.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_rich_editor_bridge.cpp @@ -235,6 +235,130 @@ ArkUINativeModuleValue RichEditorBridge::ResetSelectedBackgroundColor(ArkUIRunti return panda::JSValueRef::Undefined(vm); } +void CreateCommonEvent(EcmaVM *vm, TextCommonEvent& event, panda::Local params[]) +{ + auto eventObject = panda::ObjectRef::New(vm); + eventObject->SetNativePointerFieldCount(vm, NUM_1); + eventObject->Set(vm, panda::StringRef::NewFromUtf8(vm, "preventDefault"), + panda::FunctionRef::New(vm, Framework::JsPreventDefault)); + eventObject->SetNativePointerField(vm, NUM_0, static_cast(&event)); + params[NUM_1] = { eventObject }; +} + +ArkUINativeModuleValue RichEditorBridge::SetOnPaste(ArkUIRuntimeCallInfo* runtimeCallInfo) +{ + EcmaVM *vm = runtimeCallInfo->GetVM(); + CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm)); + Local firstArg = runtimeCallInfo->GetCallArgRef(NUM_0); + Local callbackArg = runtimeCallInfo->GetCallArgRef(NUM_1); + auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value()); + auto frameNode = reinterpret_cast(nativeNode); + CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm)); + if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) { + GetArkUINodeModifiers()->getRichEditorModifier()->resetRichEditorOnPaste(nativeNode); + return panda::JSValueRef::Undefined(vm); + } + panda::Local func = callbackArg->ToObject(vm); + std::function callback = [vm, frameNode, + func = panda::CopyableGlobal(vm, func)](TextCommonEvent& event) { + panda::LocalScope pandaScope(vm); + panda::TryCatch trycatch(vm); + PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode)); + panda::Local params[NUM_1]; + CreateCommonEvent(vm, event, params); + func->Call(vm, func.ToLocal(), params, NUM_1); + }; + GetArkUINodeModifiers()->getRichEditorModifier()->setRichEditorOnPaste( + nativeNode, reinterpret_cast(&callback)); + return panda::JSValueRef::Undefined(vm); +} + +ArkUINativeModuleValue RichEditorBridge::ResetOnPaste(ArkUIRuntimeCallInfo* runtimeCallInfo) +{ + EcmaVM* vm = runtimeCallInfo->GetVM(); + CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm)); + Local firstArg = runtimeCallInfo->GetCallArgRef(NUM_0); + auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value()); + GetArkUINodeModifiers()->getRichEditorModifier()->resetRichEditorOnPaste(nativeNode); + return panda::JSValueRef::Undefined(vm); +} + +ArkUINativeModuleValue RichEditorBridge::SetOnCut(ArkUIRuntimeCallInfo* runtimeCallInfo) +{ + EcmaVM *vm = runtimeCallInfo->GetVM(); + CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm)); + Local firstArg = runtimeCallInfo->GetCallArgRef(NUM_0); + Local callbackArg = runtimeCallInfo->GetCallArgRef(NUM_1); + auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value()); + auto frameNode = reinterpret_cast(nativeNode); + CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm)); + if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) { + GetArkUINodeModifiers()->getRichEditorModifier()->resetRichEditorOnCut(nativeNode); + return panda::JSValueRef::Undefined(vm); + } + panda::Local func = callbackArg->ToObject(vm); + std::function callback = [vm, frameNode, + func = panda::CopyableGlobal(vm, func)](TextCommonEvent& event) { + panda::LocalScope pandaScope(vm); + panda::TryCatch trycatch(vm); + PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode)); + panda::Local params[NUM_1]; + CreateCommonEvent(vm, event, params); + func->Call(vm, func.ToLocal(), params, NUM_1); + }; + GetArkUINodeModifiers()->getRichEditorModifier()->setRichEditorOnCut( + nativeNode, reinterpret_cast(&callback)); + return panda::JSValueRef::Undefined(vm); +} + +ArkUINativeModuleValue RichEditorBridge::ResetOnCut(ArkUIRuntimeCallInfo* runtimeCallInfo) +{ + EcmaVM* vm = runtimeCallInfo->GetVM(); + CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm)); + Local firstArg = runtimeCallInfo->GetCallArgRef(NUM_0); + auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value()); + GetArkUINodeModifiers()->getRichEditorModifier()->resetRichEditorOnCut(nativeNode); + return panda::JSValueRef::Undefined(vm); +} + +ArkUINativeModuleValue RichEditorBridge::SetOnCopy(ArkUIRuntimeCallInfo* runtimeCallInfo) +{ + EcmaVM *vm = runtimeCallInfo->GetVM(); + CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm)); + Local firstArg = runtimeCallInfo->GetCallArgRef(NUM_0); + Local callbackArg = runtimeCallInfo->GetCallArgRef(NUM_1); + auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value()); + auto frameNode = reinterpret_cast(nativeNode); + CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm)); + if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) { + GetArkUINodeModifiers()->getRichEditorModifier()->resetRichEditorOnCopy(nativeNode); + return panda::JSValueRef::Undefined(vm); + } + panda::Local func = callbackArg->ToObject(vm); + std::function callback = [vm, frameNode, + func = panda::CopyableGlobal(vm, func)](TextCommonEvent& event) { + panda::LocalScope pandaScope(vm); + panda::TryCatch trycatch(vm); + PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode)); + panda::Local params[NUM_1]; + CreateCommonEvent(vm, event, params); + func->Call(vm, func.ToLocal(), params, NUM_1); + }; + GetArkUINodeModifiers()->getRichEditorModifier()->setRichEditorOnCopy( + nativeNode, reinterpret_cast(&callback)); + return panda::JSValueRef::Undefined(vm); +} + +ArkUINativeModuleValue RichEditorBridge::ResetOnCopy(ArkUIRuntimeCallInfo* runtimeCallInfo) +{ + EcmaVM* vm = runtimeCallInfo->GetVM(); + CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm)); + Local firstArg = runtimeCallInfo->GetCallArgRef(NUM_0); + auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value()); + GetArkUINodeModifiers()->getRichEditorModifier()->resetRichEditorOnCopy(nativeNode); + return panda::JSValueRef::Undefined(vm); +} + ArkUINativeModuleValue RichEditorBridge::SetEnterKeyType(ArkUIRuntimeCallInfo* runtimeCallInfo) { EcmaVM* vm = runtimeCallInfo->GetVM(); diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_rich_editor_bridge.h b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_rich_editor_bridge.h index 8711daf7a67..fe8e5f29b18 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_rich_editor_bridge.h +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_rich_editor_bridge.h @@ -40,9 +40,18 @@ public: static ArkUINativeModuleValue SetSelectedBackgroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo); static ArkUINativeModuleValue ResetSelectedBackgroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo); + static ArkUINativeModuleValue SetOnPaste(ArkUIRuntimeCallInfo* runtimeCallInfo); + static ArkUINativeModuleValue ResetOnPaste(ArkUIRuntimeCallInfo* runtimeCallInfo); + + static ArkUINativeModuleValue SetOnCut(ArkUIRuntimeCallInfo* runtimeCallInfo); + static ArkUINativeModuleValue ResetOnCut(ArkUIRuntimeCallInfo* runtimeCallInfo); + + static ArkUINativeModuleValue SetOnCopy(ArkUIRuntimeCallInfo* runtimeCallInfo); + static ArkUINativeModuleValue ResetOnCopy(ArkUIRuntimeCallInfo* runtimeCallInfo); + static ArkUINativeModuleValue SetEnterKeyType(ArkUIRuntimeCallInfo* runtimeCallInfo); static ArkUINativeModuleValue ResetEnterKeyType(ArkUIRuntimeCallInfo* runtimeCallInfo); -}; + }; } #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_NATIVEMODULE_ARKTS_NATIVE_RICH_EDITOR_H \ No newline at end of file diff --git a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_ng.cpp b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_ng.cpp index 2dc56997b60..28214b8fcdc 100644 --- a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_ng.cpp @@ -182,6 +182,14 @@ void RichEditorModelNG::SetOnPaste(std::function&& f eventHub->SetOnPaste(std::move(func)); } +void RichEditorModelNG::SetOnPaste(FrameNode* frameNode, std::function&& func) +{ + CHECK_NULL_VOID(frameNode); + auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub(); + CHECK_NULL_VOID(eventHub); + eventHub->SetOnPaste(std::move(func)); +} + void RichEditorModelNG::SetPlaceholder(PlaceholderOptions& options) { if (options.value.has_value()) { @@ -340,6 +348,14 @@ void RichEditorModelNG::SetOnCut(std::function&& fun eventHub->SetOnCut(std::move(func)); } +void RichEditorModelNG::SetOnCut(FrameNode* frameNode, std::function&& func) +{ + CHECK_NULL_VOID(frameNode); + auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub(); + CHECK_NULL_VOID(eventHub); + eventHub->SetOnCut(std::move(func)); +} + void RichEditorModelNG::SetOnCopy(std::function&& func) { auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub(); @@ -347,6 +363,14 @@ void RichEditorModelNG::SetOnCopy(std::function&& fu eventHub->SetOnCopy(std::move(func)); } +void RichEditorModelNG::SetOnCopy(FrameNode* frameNode, std::function&& func) +{ + CHECK_NULL_VOID(frameNode); + auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub(); + CHECK_NULL_VOID(eventHub); + eventHub->SetOnCopy(std::move(func)); +} + void RichEditorModelNG::SetSelectionMenuOptions(const std::vector&& menuOptionsItems) { auto richEditorPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); diff --git a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_ng.h b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_ng.h index 81ae14f5222..34fca82ab5a 100644 --- a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_ng.h +++ b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_ng.h @@ -56,6 +56,9 @@ public: static void SetOnDeleteComplete(FrameNode* frameNode, std::function&& callback); static void SetOnEditingChange(FrameNode* frameNode, std::function&& callback); static void SetSelectedBackgroundColor(FrameNode* frameNode, const Color& selectedColor); + static void SetOnPaste(FrameNode* frameNode, std::function&& func); + static void SetOnCut(FrameNode* frameNode, std::function&& func); + static void SetOnCopy(FrameNode* frameNode, std::function&& func); void SetEnterKeyType(TextInputAction value) override; static void SetEnterKeyType(FrameNode* frameNode, const TextInputAction& action); void SetOnSubmit(std::function&& func) override; diff --git a/frameworks/core/interfaces/arkoala/arkoala_api.h b/frameworks/core/interfaces/arkoala/arkoala_api.h index 2a6e5a1df26..cedb7a351a3 100644 --- a/frameworks/core/interfaces/arkoala/arkoala_api.h +++ b/frameworks/core/interfaces/arkoala/arkoala_api.h @@ -3986,6 +3986,12 @@ struct ArkUIRichEditorModifier { void (*resetOnEditingChange)(ArkUINodeHandle node); void (*setRichEditorSelectedBackgroundColor)(ArkUINodeHandle node, ArkUI_Uint32 color); void (*resetRichEditorSelectedBackgroundColor)(ArkUINodeHandle node); + void (*setRichEditorOnPaste)(ArkUINodeHandle node, void* callback); + void (*resetRichEditorOnPaste)(ArkUINodeHandle node); + void (*setRichEditorOnCut)(ArkUINodeHandle node, void* callback); + void (*resetRichEditorOnCut)(ArkUINodeHandle node); + void (*setRichEditorOnCopy)(ArkUINodeHandle node, void* callback); + void (*resetRichEditorOnCopy)(ArkUINodeHandle node); void (*setRichEditorEnterKeyType)(ArkUINodeHandle node, ArkUI_Uint32 enterKeyType); void (*resetRichEditorEnterKeyType)(ArkUINodeHandle node); }; diff --git a/frameworks/core/interfaces/native/node/rich_editor_modifier.cpp b/frameworks/core/interfaces/native/node/rich_editor_modifier.cpp index e14d4d5a1c3..8d97f2d9e24 100644 --- a/frameworks/core/interfaces/native/node/rich_editor_modifier.cpp +++ b/frameworks/core/interfaces/native/node/rich_editor_modifier.cpp @@ -149,6 +149,63 @@ void ResetRichEditorSelectedBackgroundColor(ArkUINodeHandle node) RichEditorModelNG::SetSelectedBackgroundColor(frameNode, selectedBackgroundColor); } +void SetRichEditorOnPaste(ArkUINodeHandle node, void* callback) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + if (callback) { + auto onPaste = reinterpret_cast*>(callback); + RichEditorModelNG::SetOnPaste(frameNode, std::move(*onPaste)); + } else { + RichEditorModelNG::SetOnPaste(frameNode, nullptr); + } +} + +void ResetRichEditorOnPaste(ArkUINodeHandle node) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + RichEditorModelNG::SetOnPaste(frameNode, nullptr); +} + +void SetRichEditorOnCut(ArkUINodeHandle node, void* callback) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + if (callback) { + auto onCut = reinterpret_cast*>(callback); + RichEditorModelNG::SetOnCut(frameNode, std::move(*onCut)); + } else { + RichEditorModelNG::SetOnCut(frameNode, nullptr); + } +} + +void ResetRichEditorOnCut(ArkUINodeHandle node) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + RichEditorModelNG::SetOnCut(frameNode, nullptr); +} + +void SetRichEditorOnCopy(ArkUINodeHandle node, void* callback) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + if (callback) { + auto onCopy = reinterpret_cast*>(callback); + RichEditorModelNG::SetOnCopy(frameNode, std::move(*onCopy)); + } else { + RichEditorModelNG::SetOnCopy(frameNode, nullptr); + } +} + +void ResetRichEditorOnCopy(ArkUINodeHandle node) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + RichEditorModelNG::SetOnCopy(frameNode, nullptr); +} + void SetRichEditorEnterKeyType(ArkUINodeHandle node, ArkUI_Uint32 enterKeyType) { auto* frameNode = reinterpret_cast(node); @@ -171,8 +228,9 @@ const ArkUIRichEditorModifier* GetRichEditorModifier() SetRichEditorCopyOptions, ResetRichEditorCopyOptions, SetRichEditorCaretColor, ResetRichEditorCaretColor, SetRichEditorOnReady, ResetRichEditorOnReady, SetRichEditorOnDeleteComplete, ResetRichEditorOnDeleteComplete, SetRichEditorOnEditingChange, ResetRichEditorOnEditingChange, - SetRichEditorSelectedBackgroundColor, ResetRichEditorSelectedBackgroundColor, SetRichEditorEnterKeyType, - ResetRichEditorEnterKeyType }; + SetRichEditorSelectedBackgroundColor, ResetRichEditorSelectedBackgroundColor, SetRichEditorOnPaste, + ResetRichEditorOnPaste, SetRichEditorOnCut, ResetRichEditorOnCut, SetRichEditorOnCopy, ResetRichEditorOnCopy, + SetRichEditorEnterKeyType, ResetRichEditorEnterKeyType }; return &modifier; } } -- Gitee