Skip to content

Commit 9789372

Browse files
committed
fix: improve suggestion handling for chinese input, fix #1449
1 parent 2644bb8 commit 9789372

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

packages/suggestion/src/suggestion.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,28 @@ export function Suggestion({
137137
range: {},
138138
query: null,
139139
text: null,
140+
composing: false,
140141
}
141142
},
142143

143144
// Apply changes to the plugin state from a view transaction.
144145
apply(transaction, prev) {
146+
const { composing } = editor.view
145147
const { selection } = transaction
148+
const { empty, from } = selection
146149
const next = { ...prev }
147150

151+
next.composing = composing
152+
148153
// We can only be suggesting if there is no selection
149-
if (selection.from === selection.to) {
154+
// or a composition is active (see: https://github.com/ueberdosis/tiptap/issues/1449)
155+
if (empty || editor.view.composing) {
150156
// Reset active state if we just left the previous suggestion range
151-
if (selection.from < prev.range.from || selection.from > prev.range.to) {
157+
if (
158+
(from < prev.range.from || from > prev.range.to)
159+
&& !composing
160+
&& !prev.composing
161+
) {
152162
next.active = false
153163
}
154164

0 commit comments

Comments
 (0)