Skip to content

Commit

Permalink
Fix mention input targetRange
Browse files Browse the repository at this point in the history
  • Loading branch information
JannesMeyer committed Nov 19, 2023
1 parent 0389228 commit 3acfad9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/blue-rules-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@udecode/plate-mention': patch
---

Fix combobox targetRange to account for normalization
15 changes: 10 additions & 5 deletions packages/mention/src/withMention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' &&
Expand Down

0 comments on commit 3acfad9

Please sign in to comment.