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