From 7499d4b4c01a089906a96f30f6c04256204ca65e Mon Sep 17 00:00:00 2001 From: yongzs <673262625@qq.com> Date: Mon, 7 Mar 2022 18:58:34 +0800 Subject: [PATCH] fixed cursor when we triple click on text and type over it #4862 (#4868) * fixed cursor when we triple click on text and type over it * fixed * fixed * Add changeset Co-authored-by: Dylan Schiemann --- .changeset/healthy-wasps-sit.md | 5 +++++ packages/slate-react/src/components/editable.tsx | 7 +++++++ 2 files changed, 12 insertions(+) create mode 100644 .changeset/healthy-wasps-sit.md diff --git a/.changeset/healthy-wasps-sit.md b/.changeset/healthy-wasps-sit.md new file mode 100644 index 000000000..c59a87012 --- /dev/null +++ b/.changeset/healthy-wasps-sit.md @@ -0,0 +1,5 @@ +--- +'slate-react: patch +--- + +fixed cursor when triple clicking on text and type over it, fixes #4862 diff --git a/packages/slate-react/src/components/editable.tsx b/packages/slate-react/src/components/editable.tsx index 2662835c6..49396a7d0 100644 --- a/packages/slate-react/src/components/editable.tsx +++ b/packages/slate-react/src/components/editable.tsx @@ -483,6 +483,13 @@ export const Editable = (props: EditableProps) => { case 'insertFromYank': case 'insertReplacementText': case 'insertText': { + const { selection } = editor + if (selection) { + if (Range.isExpanded(selection)) { + Editor.deleteFragment(editor) + } + } + if (type === 'insertFromComposition') { // COMPAT: in Safari, `compositionend` is dispatched after the // `beforeinput` for "insertFromComposition". But if we wait for it