Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add customCopy event handler for copy #484

Merged
merged 2 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/tasty-dragons-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@wangeditor-next/editor': patch
'@wangeditor-next/core': patch
---

feat: add customCopy event handler for copy
4 changes: 4 additions & 0 deletions packages/core/src/config/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ export interface IEditorConfig {
* 自定义粘贴。返回 true 则继续粘贴,返回 false 则自行实现粘贴,阻止默认粘贴
*/
customPaste?: (editor: IDomEditor, e: ClipboardEvent) => boolean
/**
* 自定义复制。拦截 event 添加或修改 clipboardData 数据
*/
customCopy?: (editor: IDomEditor, e: ClipboardEvent) => void

// edit state
scroll: boolean
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/text-area/event-handlers/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ function handleOnCopy(e: Event, _textarea: TextArea, editor: IDomEditor) {

if (data == null) { return }
editor.setFragmentData(data)

const { customCopy } = editor.getConfig()

if (customCopy) {
customCopy(editor, event)
}
}

export default handleOnCopy
Loading