Skip to content

Commit

Permalink
fix: prevent suggestions from being active when editor is readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Sidwell committed Apr 9, 2022
1 parent ab4a0e2 commit c680cca
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/suggestion/src/suggestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,18 @@ 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
const next = { ...prev }

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)
Expand Down

0 comments on commit c680cca

Please sign in to comment.