diff --git a/.changeset/blue-rules-attack.md b/.changeset/blue-rules-attack.md new file mode 100644 index 0000000000..fd011fdfd5 --- /dev/null +++ b/.changeset/blue-rules-attack.md @@ -0,0 +1,5 @@ +--- +'@udecode/plate-mention': patch +--- + +Fix combobox targetRange to account for normalization diff --git a/packages/mention/src/withMention.ts b/packages/mention/src/withMention.ts index ddadf493ce..72f2afba12 100644 --- a/packages/mention/src/withMention.ts +++ b/packages/mention/src/withMention.ts @@ -180,11 +180,16 @@ export const withMention = < focus: { path: operation.path.concat([0]), offset: text.length }, }); - comboboxActions.open({ - activeId: id!, - text, - targetRange: editor.selection, - }); + // Make sure that we read the updated selection after normalization. + // Slate may insert an empty text node before or after the mention input + // during normalization. + setTimeout(() => { + comboboxActions.open({ + activeId: id!, + text, + targetRange: editor.selection, + }); + }, 0); } } else if ( operation.type === 'remove_node' &&