From 45990cdc0f8c9b7d31fe31cabe4b29088851d9f6 Mon Sep 17 00:00:00 2001 From: Scott Sidwell Date: Fri, 8 Apr 2022 14:50:50 +1000 Subject: [PATCH] fix: prevent suggestions from being active when editor is readonly --- packages/suggestion/src/suggestion.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/suggestion/src/suggestion.ts b/packages/suggestion/src/suggestion.ts index 12baee739..a1763448c 100644 --- a/packages/suggestion/src/suggestion.ts +++ b/packages/suggestion/src/suggestion.ts @@ -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)