Skip to content

Commit

Permalink
feat: add customCopy event handler for copy
Browse files Browse the repository at this point in the history
functionality
  • Loading branch information
cycleccc committed Dec 31, 2024
1 parent 3d95f5d commit dfd02e3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
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

0 comments on commit dfd02e3

Please sign in to comment.