From c1e3fbaab969f2e78303f9ba00f26b88c575cdd1 Mon Sep 17 00:00:00 2001 From: Eric Meier Date: Wed, 20 Apr 2022 17:47:38 -0400 Subject: [PATCH] Don't treat events with non-selection target range as native (#4957) --- .changeset/twenty-papayas-vanish.md | 5 +++++ packages/slate-react/src/components/editable.tsx | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 .changeset/twenty-papayas-vanish.md diff --git a/.changeset/twenty-papayas-vanish.md b/.changeset/twenty-papayas-vanish.md new file mode 100644 index 000000000..ce2ce9714 --- /dev/null +++ b/.changeset/twenty-papayas-vanish.md @@ -0,0 +1,5 @@ +--- +'slate-react': patch +--- + +Don't treat events with non-selection target range as native diff --git a/packages/slate-react/src/components/editable.tsx b/packages/slate-react/src/components/editable.tsx index 2a9ea459e..509228978 100644 --- a/packages/slate-react/src/components/editable.tsx +++ b/packages/slate-react/src/components/editable.tsx @@ -390,10 +390,6 @@ export const Editable = (props: EditableProps) => { } } - if (!native) { - event.preventDefault() - } - // COMPAT: For the deleting forward/backward input types we don't want // to change the selection because it is the range that will be deleted, // and those commands determine that for themselves. @@ -407,6 +403,8 @@ export const Editable = (props: EditableProps) => { }) if (!selection || !Range.equals(selection, range)) { + native = false + const selectionRef = editor.selection && Editor.rangeRef(editor, editor.selection) @@ -419,6 +417,10 @@ export const Editable = (props: EditableProps) => { } } + if (!native) { + event.preventDefault() + } + // COMPAT: If the selection is expanded, even if the command seems like // a delete forward/backward command it should delete the selection. if (