mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-09-01 19:22:35 +02:00
fix getFragmentByRange logic for same text node, closes #1123
This commit is contained in:
@@ -743,18 +743,24 @@ class Node {
|
|||||||
|
|
||||||
while (parent = node.getParent(child.key)) {
|
while (parent = node.getParent(child.key)) {
|
||||||
const index = parent.nodes.indexOf(child)
|
const index = parent.nodes.indexOf(child)
|
||||||
const position = child.kind == 'text' ? startOffset : child.nodes.indexOf(previous)
|
const position = child.kind == 'text'
|
||||||
|
? startOffset
|
||||||
|
: child.nodes.indexOf(previous)
|
||||||
|
|
||||||
parent = parent.splitNode(index, position)
|
parent = parent.splitNode(index, position)
|
||||||
node = node.updateNode(parent)
|
node = node.updateNode(parent)
|
||||||
previous = parent.nodes.get(index + 1)
|
previous = parent.nodes.get(index + 1)
|
||||||
child = parent
|
child = parent
|
||||||
}
|
}
|
||||||
|
|
||||||
child = endText
|
child = startKey == endKey ? node.getNextText(startKey) : endText
|
||||||
|
|
||||||
while (parent = node.getParent(child.key)) {
|
while (parent = node.getParent(child.key)) {
|
||||||
const index = parent.nodes.indexOf(child)
|
const index = parent.nodes.indexOf(child)
|
||||||
const position = child.kind == 'text' ? endOffset : child.nodes.indexOf(previous)
|
const position = child.kind == 'text'
|
||||||
|
? startKey == endKey ? endOffset - startOffset : endOffset
|
||||||
|
: child.nodes.indexOf(previous)
|
||||||
|
|
||||||
parent = parent.splitNode(index, position)
|
parent = parent.splitNode(index, position)
|
||||||
node = node.updateNode(parent)
|
node = node.updateNode(parent)
|
||||||
previous = parent.nodes.get(index + 1)
|
previous = parent.nodes.get(index + 1)
|
||||||
@@ -762,16 +768,15 @@ class Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the start and end nodes.
|
// Get the start and end nodes.
|
||||||
const next = node.getNextText(node.getNextText(startKey).key)
|
|
||||||
const startNode = node.getNextSibling(node.getFurthestAncestor(startKey).key)
|
const startNode = node.getNextSibling(node.getFurthestAncestor(startKey).key)
|
||||||
const endNode = startKey == endKey
|
const endNode = startKey == endKey
|
||||||
? node.getFurthestAncestor(next.key)
|
? node.getNextSibling(node.getNextSibling(node.getFurthestAncestor(endKey).key).key)
|
||||||
: node.getFurthestAncestor(endKey)
|
: node.getNextSibling(node.getFurthestAncestor(endKey).key)
|
||||||
|
|
||||||
// Get children range of nodes from start to end nodes
|
// Get children range of nodes from start to end nodes
|
||||||
const startIndex = node.nodes.indexOf(startNode)
|
const startIndex = node.nodes.indexOf(startNode)
|
||||||
const endIndex = node.nodes.indexOf(endNode)
|
const endIndex = node.nodes.indexOf(endNode)
|
||||||
const nodes = node.nodes.slice(startIndex, endIndex + 1)
|
const nodes = node.nodes.slice(startIndex, endIndex)
|
||||||
|
|
||||||
// Return a new document fragment.
|
// Return a new document fragment.
|
||||||
return Document.create({ nodes })
|
return Document.create({ nodes })
|
||||||
|
Reference in New Issue
Block a user