mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-30 02:19:52 +02:00
fix: Search backward and forward for leaf nodes in non contenteditable elements (#5936)
* Search backward and forward for leaf nodes in non contenteditable elements * Add changeset --------- Co-authored-by: Raffael Wannenmacher <raffael.wannenmacher@tx.group>
This commit is contained in:
5
.changeset/real-clouds-accept.md
Normal file
5
.changeset/real-clouds-accept.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'slate-dom': patch
|
||||
---
|
||||
|
||||
Search backward and forward for leaf nodes in non contenteditable elements inside `toSlatePoint`
|
@@ -697,7 +697,7 @@ export const DOMEditor: DOMEditorInterface = {
|
||||
searchDirection?: 'forward' | 'backward'
|
||||
}
|
||||
): T extends true ? Point | null : Point => {
|
||||
const { exactMatch, suppressThrow, searchDirection = 'backward' } = options
|
||||
const { exactMatch, suppressThrow, searchDirection } = options
|
||||
const [nearestNode, nearestOffset] = exactMatch
|
||||
? domPoint
|
||||
: normalizeDOMPoint(domPoint)
|
||||
@@ -812,20 +812,32 @@ export const DOMEditor: DOMEditorInterface = {
|
||||
'[data-slate-node="element"]'
|
||||
)
|
||||
|
||||
if (searchDirection === 'forward') {
|
||||
const leafNodes = [
|
||||
...getLeafNodes(elementNode),
|
||||
...getLeafNodes(elementNode?.nextElementSibling),
|
||||
]
|
||||
leafNode =
|
||||
leafNodes.find(leaf => isAfter(nonEditableNode, leaf)) ?? null
|
||||
} else {
|
||||
if (searchDirection === 'backward' || !searchDirection) {
|
||||
const leafNodes = [
|
||||
...getLeafNodes(elementNode?.previousElementSibling),
|
||||
...getLeafNodes(elementNode),
|
||||
]
|
||||
|
||||
leafNode =
|
||||
leafNodes.findLast(leaf => isBefore(nonEditableNode, leaf)) ?? null
|
||||
|
||||
if (leafNode) {
|
||||
searchDirection === 'backward'
|
||||
}
|
||||
}
|
||||
|
||||
if (searchDirection === 'forward' || !searchDirection) {
|
||||
const leafNodes = [
|
||||
...getLeafNodes(elementNode),
|
||||
...getLeafNodes(elementNode?.nextElementSibling),
|
||||
]
|
||||
|
||||
leafNode =
|
||||
leafNodes.find(leaf => isAfter(nonEditableNode, leaf)) ?? null
|
||||
|
||||
if (leafNode) {
|
||||
searchDirection === 'forward'
|
||||
}
|
||||
}
|
||||
|
||||
if (leafNode) {
|
||||
|
Reference in New Issue
Block a user