fix: prevent suggestions from being active when editor is readonly

This commit is contained in:
Scott Sidwell 2022-04-08 14:50:50 +10:00
parent ab4a0e2507
commit 45990cdc0f

View File

@ -169,6 +169,7 @@ export function Suggestion({
// Apply changes to the plugin state from a view transaction.
apply(transaction, prev, oldState, state) {
const { isEditable } = editor
const { composing } = editor.view
const { selection } = transaction
const { empty, from } = selection
@ -176,9 +177,10 @@ export function Suggestion({
next.composing = composing
// We can only be suggesting if there is no selection
// or a composition is active (see: https://github.com/ueberdosis/tiptap/issues/1449)
if (empty || editor.view.composing) {
// We can only be suggesting if the view is editable, and:
// * there is no selection, or
// * a composition is active (see: https://github.com/ueberdosis/tiptap/issues/1449)
if (isEditable && (empty || editor.view.composing)) {
// Reset active state if we just left the previous suggestion range
if (
(from < prev.range.from || from > prev.range.to)