1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-04-21 13:51:59 +02:00

Fixed Triple click selection and copy&paste in read-only mode ()

* Fixed Triple click selection and copy&paste in read-only mode

* Create khaki-candles-serve.md

* Update editable.tsx

make sense

* fixed 3871

* Update .changeset/khaki-candles-serve.md

* Update .changeset/khaki-candles-serve.md

Co-authored-by: Dylan Schiemann <dylan@dojotoolkit.org>
This commit is contained in:
yongzs 2022-04-04 00:09:03 +08:00 committed by GitHub
parent f6b7ca1f97
commit aff67312cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 2 deletions
.changeset
packages/slate-react/src

@ -0,0 +1,6 @@
---
'slate-react': patch
'slate': patch
---
Fixed Triple click selection and copy&paste in read-only mode

@ -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
@ -753,13 +754,23 @@ export const Editable = (props: EditableProps) => {
onClick={useCallback(
(event: React.MouseEvent<HTMLDivElement>) => {
if (
!readOnly &&
hasTarget(editor, event.target) &&
!isEventHandled(event, attributes.onClick) &&
isDOMNode(event.target)
) {
const node = ReactEditor.toSlateNode(editor, event.target)
const path = ReactEditor.findPath(editor, node)
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)
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.
@ -770,7 +781,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 })

@ -0,0 +1 @@
export const TRIPLE_CLICK = 3