mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-11 09:43:58 +02:00
Fixed Triple click selection and copy&paste in read-only mode (#4914)
* 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:
6
.changeset/khaki-candles-serve.md
Normal file
6
.changeset/khaki-candles-serve.md
Normal file
@@ -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_WINDOW,
|
||||||
EDITOR_TO_USER_SELECTION,
|
EDITOR_TO_USER_SELECTION,
|
||||||
} from '../utils/weak-maps'
|
} from '../utils/weak-maps'
|
||||||
|
import { TRIPLE_CLICK } from '../utils/constants'
|
||||||
|
|
||||||
type DeferredOperation = () => void
|
type DeferredOperation = () => void
|
||||||
|
|
||||||
@@ -753,13 +754,23 @@ export const Editable = (props: EditableProps) => {
|
|||||||
onClick={useCallback(
|
onClick={useCallback(
|
||||||
(event: React.MouseEvent<HTMLDivElement>) => {
|
(event: React.MouseEvent<HTMLDivElement>) => {
|
||||||
if (
|
if (
|
||||||
!readOnly &&
|
|
||||||
hasTarget(editor, event.target) &&
|
hasTarget(editor, event.target) &&
|
||||||
!isEventHandled(event, attributes.onClick) &&
|
!isEventHandled(event, attributes.onClick) &&
|
||||||
isDOMNode(event.target)
|
isDOMNode(event.target)
|
||||||
) {
|
) {
|
||||||
const node = ReactEditor.toSlateNode(editor, event.target)
|
const node = ReactEditor.toSlateNode(editor, event.target)
|
||||||
const path = ReactEditor.findPath(editor, node)
|
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,
|
// At this time, the Slate document may be arbitrarily different,
|
||||||
// because onClick handlers can change the document before we get here.
|
// because onClick handlers can change the document before we get here.
|
||||||
@@ -770,7 +781,6 @@ export const Editable = (props: EditableProps) => {
|
|||||||
if (lookupNode === node) {
|
if (lookupNode === node) {
|
||||||
const start = Editor.start(editor, path)
|
const start = Editor.start(editor, path)
|
||||||
const end = Editor.end(editor, path)
|
const end = Editor.end(editor, path)
|
||||||
|
|
||||||
const startVoid = Editor.void(editor, { at: start })
|
const startVoid = Editor.void(editor, { at: start })
|
||||||
const endVoid = Editor.void(editor, { at: end })
|
const endVoid = Editor.void(editor, { at: end })
|
||||||
|
|
||||||
|
1
packages/slate-react/src/utils/constants.ts
Normal file
1
packages/slate-react/src/utils/constants.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export const TRIPLE_CLICK = 3
|
Reference in New Issue
Block a user