mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-09-03 12:12:39 +02:00
Merge branch 'cdd-master'
This commit is contained in:
@@ -254,9 +254,19 @@ const Node = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
getBlocksAtRangeAsArray(range) {
|
getBlocksAtRangeAsArray(range) {
|
||||||
return this
|
range = range.normalize(this)
|
||||||
.getTextsAtRangeAsArray(range)
|
const { startKey, endKey } = range
|
||||||
.map(text => this.getClosestBlock(text.key))
|
const startBlock = this.getClosestBlock(startKey)
|
||||||
|
|
||||||
|
// PERF: the most common case is when the range is in a single block node,
|
||||||
|
// where we can avoid a lot of iterating of the tree.
|
||||||
|
if (startKey == endKey) return [startBlock]
|
||||||
|
|
||||||
|
const endBlock = this.getClosestBlock(endKey)
|
||||||
|
const blocks = this.getBlocksAsArray()
|
||||||
|
const start = blocks.indexOf(startBlock)
|
||||||
|
const end = blocks.indexOf(endBlock)
|
||||||
|
return blocks.slice(start, end + 1)
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user