Skip to content

Commit

Permalink
fix( text-paste issue 4376): 修复 maxLength 最大字数对外部粘贴进的文本无效
Browse files Browse the repository at this point in the history
  • Loading branch information
cycleccc committed Apr 10, 2024
1 parent f35d8a7 commit be6aa2e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/editor/plugins/with-event-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { isDOMText, getPlainText } from '../../utils/dom'

export const withEventData = <T extends Editor>(editor: T) => {
const e = editor as T & IDomEditor
const { insertText, insertFragment } = e

e.setFragmentData = (data: Pick<DataTransfer, 'getData' | 'setData'>) => {
const { selection } = e
Expand Down Expand Up @@ -102,6 +101,7 @@ export const withEventData = <T extends Editor>(editor: T) => {

e.insertData = (data: DataTransfer) => {
const fragment = data.getData('application/x-slate-fragment')
// 只有从编辑器中内复制的内容,才会获取 fragment,从其他地方粘贴到编辑器中,不会获取 fragment
if (fragment) {
const decoded = decodeURIComponent(window.atob(fragment))
const parsed = JSON.parse(decoded) as Node[]
Expand All @@ -127,7 +127,7 @@ export const withEventData = <T extends Editor>(editor: T) => {
Transforms.splitNodes(e, { always: true })
}

insertText(line)
e.insertText(line)
split = true
}
return
Expand Down

0 comments on commit be6aa2e

Please sign in to comment.