From 9789372cea901b21059d53c30ff301efb35fb720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 13 Aug 2021 15:13:19 +0200 Subject: [PATCH] fix: improve suggestion handling for chinese input, fix #1449 --- packages/suggestion/src/suggestion.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/suggestion/src/suggestion.ts b/packages/suggestion/src/suggestion.ts index 6fd508a2..06613a18 100644 --- a/packages/suggestion/src/suggestion.ts +++ b/packages/suggestion/src/suggestion.ts @@ -137,18 +137,28 @@ export function Suggestion({ range: {}, query: null, text: null, + composing: false, } }, // Apply changes to the plugin state from a view transaction. apply(transaction, prev) { + 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 - if (selection.from === selection.to) { + // or a composition is active (see: https://github.com/ueberdosis/tiptap/issues/1449) + if (empty || editor.view.composing) { // Reset active state if we just left the previous suggestion range - if (selection.from < prev.range.from || selection.from > prev.range.to) { + if ( + (from < prev.range.from || from > prev.range.to) + && !composing + && !prev.composing + ) { next.active = false }