diff --git a/packages/core/src/editor/plugins/with-content.ts b/packages/core/src/editor/plugins/with-content.ts index da0d544c2..e227afaf0 100644 --- a/packages/core/src/editor/plugins/with-content.ts +++ b/packages/core/src/editor/plugins/with-content.ts @@ -33,15 +33,19 @@ export const withContent = (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':