fix: improve suggestion handling for chinese input, fix #1449
This commit is contained in:
@@ -137,18 +137,28 @@ export function Suggestion({
|
|||||||
range: {},
|
range: {},
|
||||||
query: null,
|
query: null,
|
||||||
text: null,
|
text: null,
|
||||||
|
composing: false,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// Apply changes to the plugin state from a view transaction.
|
// Apply changes to the plugin state from a view transaction.
|
||||||
apply(transaction, prev) {
|
apply(transaction, prev) {
|
||||||
|
const { composing } = editor.view
|
||||||
const { selection } = transaction
|
const { selection } = transaction
|
||||||
|
const { empty, from } = selection
|
||||||
const next = { ...prev }
|
const next = { ...prev }
|
||||||
|
|
||||||
|
next.composing = composing
|
||||||
|
|
||||||
// We can only be suggesting if there is no selection
|
// 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
|
// 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
|
next.active = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user