From 694ea3153abedfa210a0dde55ef632bcea3d0acd Mon Sep 17 00:00:00 2001 From: yongzs <673262625@qq.com> Date: Fri, 25 Mar 2022 12:27:52 +0800 Subject: [PATCH 1/6] Fixed Triple click selection and copy&paste in read-only mode --- packages/slate-react/src/components/editable.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/slate-react/src/components/editable.tsx b/packages/slate-react/src/components/editable.tsx index 65f92eef8c..a3b2c76895 100644 --- a/packages/slate-react/src/components/editable.tsx +++ b/packages/slate-react/src/components/editable.tsx @@ -733,7 +733,6 @@ export const Editable = (props: EditableProps) => { onClick={useCallback( (event: React.MouseEvent) => { if ( - !readOnly && hasTarget(editor, event.target) && !isEventHandled(event, attributes.onClick) && isDOMNode(event.target) @@ -741,6 +740,18 @@ export const Editable = (props: EditableProps) => { const node = ReactEditor.toSlateNode(editor, event.target) const path = ReactEditor.findPath(editor, node) + if (event.detail === 3 && readOnly) { + const start = Editor.start(editor, [path[0]]) + const end = Editor.end(editor, [path[0]]) + const range = Editor.range(editor, start, end) + Transforms.select(editor, range) + return + } + + if (readOnly) { + return + } + // At this time, the Slate document may be arbitrarily different, // because onClick handlers can change the document before we get here. // Therefore we must check that this path actually exists, @@ -750,7 +761,6 @@ export const Editable = (props: EditableProps) => { if (lookupNode === node) { const start = Editor.start(editor, path) const end = Editor.end(editor, path) - const startVoid = Editor.void(editor, { at: start }) const endVoid = Editor.void(editor, { at: end }) From 350ebee9a975efeba50ed12fbd88acfd2014b1a8 Mon Sep 17 00:00:00 2001 From: yongzs <673262625@qq.com> Date: Tue, 29 Mar 2022 21:46:44 +0800 Subject: [PATCH 2/6] Create khaki-candles-serve.md --- .changeset/khaki-candles-serve.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/khaki-candles-serve.md diff --git a/.changeset/khaki-candles-serve.md b/.changeset/khaki-candles-serve.md new file mode 100644 index 0000000000..b51acfb90a --- /dev/null +++ b/.changeset/khaki-candles-serve.md @@ -0,0 +1,6 @@ +--- +"slate-react": patch +"slate": patch +--- + +Fixed Triple click selection and copy&paste in read-only mode From b9ba27866e28aed18b27f19e6969faf6a3bc79b7 Mon Sep 17 00:00:00 2001 From: yongzs <673262625@qq.com> Date: Tue, 29 Mar 2022 21:55:33 +0800 Subject: [PATCH 3/6] Update editable.tsx make sense --- packages/slate-react/src/components/editable.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/slate-react/src/components/editable.tsx b/packages/slate-react/src/components/editable.tsx index a3b2c76895..6670c7fa49 100644 --- a/packages/slate-react/src/components/editable.tsx +++ b/packages/slate-react/src/components/editable.tsx @@ -739,8 +739,8 @@ export const Editable = (props: EditableProps) => { ) { const node = ReactEditor.toSlateNode(editor, event.target) const path = ReactEditor.findPath(editor, node) - - if (event.detail === 3 && readOnly) { + const TRIPLE_CLICK = 3 + if (event.detail === TRIPLE_CLICK && readOnly) { const start = Editor.start(editor, [path[0]]) const end = Editor.end(editor, [path[0]]) const range = Editor.range(editor, start, end) From 91261f16fe68c915ab40dc8004bfbfabe4f18f41 Mon Sep 17 00:00:00 2001 From: yongzs <673262625@qq.com> Date: Sat, 2 Apr 2022 14:26:24 +0800 Subject: [PATCH 4/6] fixed 3871 --- packages/slate-react/src/components/editable.tsx | 4 ++-- packages/slate-react/src/utils/constants.ts | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 packages/slate-react/src/utils/constants.ts diff --git a/packages/slate-react/src/components/editable.tsx b/packages/slate-react/src/components/editable.tsx index 0832a89e0f..5a37fd334f 100644 --- a/packages/slate-react/src/components/editable.tsx +++ b/packages/slate-react/src/components/editable.tsx @@ -54,6 +54,7 @@ import { EDITOR_TO_WINDOW, EDITOR_TO_USER_SELECTION, } from '../utils/weak-maps' +import { TRIPLE_CLICK } from '../utils/constants' type DeferredOperation = () => void @@ -759,8 +760,7 @@ export const Editable = (props: EditableProps) => { ) { const node = ReactEditor.toSlateNode(editor, event.target) const path = ReactEditor.findPath(editor, node) - const TRIPLE_CLICK = 3 - if (event.detail === TRIPLE_CLICK && readOnly) { + if (event.detail === TRIPLE_CLICK) { const start = Editor.start(editor, [path[0]]) const end = Editor.end(editor, [path[0]]) const range = Editor.range(editor, start, end) diff --git a/packages/slate-react/src/utils/constants.ts b/packages/slate-react/src/utils/constants.ts new file mode 100644 index 0000000000..a8a13e355d --- /dev/null +++ b/packages/slate-react/src/utils/constants.ts @@ -0,0 +1 @@ +export const TRIPLE_CLICK = 3 From 53647b36f260f58488ab92af9cbefe2e21b4cfdb Mon Sep 17 00:00:00 2001 From: Dylan Schiemann Date: Sun, 3 Apr 2022 08:26:23 -0700 Subject: [PATCH 5/6] Update .changeset/khaki-candles-serve.md --- .changeset/khaki-candles-serve.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/khaki-candles-serve.md b/.changeset/khaki-candles-serve.md index b51acfb90a..968d8d6ca2 100644 --- a/.changeset/khaki-candles-serve.md +++ b/.changeset/khaki-candles-serve.md @@ -1,5 +1,5 @@ --- -"slate-react": patch +'slate-react': patch "slate": patch --- From 1c369c8e34ecee4f04c4decee8780c771aabb6c2 Mon Sep 17 00:00:00 2001 From: Dylan Schiemann Date: Sun, 3 Apr 2022 08:26:38 -0700 Subject: [PATCH 6/6] Update .changeset/khaki-candles-serve.md --- .changeset/khaki-candles-serve.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/khaki-candles-serve.md b/.changeset/khaki-candles-serve.md index 968d8d6ca2..9be347c050 100644 --- a/.changeset/khaki-candles-serve.md +++ b/.changeset/khaki-candles-serve.md @@ -1,6 +1,6 @@ --- 'slate-react': patch -"slate": patch +'slate': patch --- Fixed Triple click selection and copy&paste in read-only mode