Skip to content

Commit

Permalink
Merge pull request #4139 from wangeditor-team/fix-readonly
Browse files Browse the repository at this point in the history
fix: 修复 readonly 模式下,特定内容下editor初始化报错的问题
  • Loading branch information
wangfupeng1988 authored May 6, 2022
2 parents 0719831 + f3bc8b8 commit 226e836
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/core/src/editor/plugins/with-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@ export const withContent = <T extends Editor>(editor: T) => {
const e = editor as T & IDomEditor
const { onChange, insertText, apply, deleteBackward } = e

e.insertText = (text: string) => {
const { readOnly } = e.getConfig()
if (readOnly) return

insertText(text)
}

// 重写 apply 方法
// apply 方法非常重要,它最终执行 operation https://docs.slatejs.org/concepts/05-operations
// operation 的接口定义参考 slate src/interfaces/operation.ts
e.apply = (op: Operation) => {
const matches: [Path, Key][] = []

const { readOnly } = e.getConfig()
if (readOnly) return

switch (op.type) {
case 'insert_text':
case 'remove_text':
Expand Down

0 comments on commit 226e836

Please sign in to comment.