mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-21 14:41:23 +02:00
Fix: regression caused by triple click fix (#4498)
* fix: check if data-slate-tring node is not null Only reset the focus node of a selection when the node with attribute `data-slate-string` is defined * fix: rewrite logic for checking triple click * Add changeset Co-authored-by: Dylan Schiemann <dylan@dojotoolkit.org>
This commit is contained in:
5
.changeset/smart-pears-beam.md
Normal file
5
.changeset/smart-pears-beam.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'slate-react': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix: regression caused by triple click fix
|
@@ -565,13 +565,17 @@ export const ReactEditor = {
|
|||||||
// This will highlight the corresponding toolbar button for the sibling
|
// This will highlight the corresponding toolbar button for the sibling
|
||||||
// block even though users just want to target the previous block.
|
// block even though users just want to target the previous block.
|
||||||
// (2021/08/24)
|
// (2021/08/24)
|
||||||
// Within the context of Slate and Chrome, if anchor and focus nodes don't have
|
// Signs of a triple click in Chrome
|
||||||
// the same nodeValue and focusOffset is 0, then it's definitely a triple click
|
// - anchor node will be a text node but focus node won't
|
||||||
// behaviour.
|
// - both anchorOffset and focusOffset are 0
|
||||||
|
// - focusNode value will be null since Chrome tries to extend to just the
|
||||||
|
// beginning of the next block
|
||||||
if (
|
if (
|
||||||
IS_CHROME &&
|
IS_CHROME &&
|
||||||
anchorNode?.nodeValue !== focusNode?.nodeValue &&
|
anchorNode?.nodeType !== focusNode?.nodeType &&
|
||||||
domRange.focusOffset === 0
|
domRange.anchorOffset === 0 &&
|
||||||
|
domRange.focusOffset === 0 &&
|
||||||
|
focusNode?.nodeValue == null
|
||||||
) {
|
) {
|
||||||
// If an anchorNode is an element node when triple clicked, then the focusNode
|
// If an anchorNode is an element node when triple clicked, then the focusNode
|
||||||
// should also be the same as anchorNode when triple clicked.
|
// should also be the same as anchorNode when triple clicked.
|
||||||
@@ -590,11 +594,15 @@ export const ReactEditor = {
|
|||||||
)
|
)
|
||||||
const focusElement = tripleClickedBlock!.lastElementChild
|
const focusElement = tripleClickedBlock!.lastElementChild
|
||||||
// Get the element node that holds the focus text node
|
// Get the element node that holds the focus text node
|
||||||
|
// Not every Slate element node contains a child node with `data-slate-string`,
|
||||||
|
// such as void nodes, so the result below could be null.
|
||||||
const innermostFocusElement = focusElement!.querySelector(
|
const innermostFocusElement = focusElement!.querySelector(
|
||||||
'[data-slate-string]'
|
'[data-slate-string]'
|
||||||
)
|
)
|
||||||
const lastTextNode = innermostFocusElement!.childNodes[0]
|
if (innermostFocusElement) {
|
||||||
focusNode = lastTextNode
|
const lastTextNode = innermostFocusElement.childNodes[0]
|
||||||
|
focusNode = lastTextNode
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user