fix: improve performance for isActive method, see #1930

This commit is contained in:
Philipp Kühn
2021-09-22 19:43:55 +02:00
parent 6fa886273f
commit fcca1e6f4d
5 changed files with 14 additions and 14 deletions

View File

@@ -14,18 +14,18 @@ export default function isNodeActive(
? getNodeType(typeOrName, state.schema)
: null
let nodeRanges: NodeRange[] = []
const nodeRanges: NodeRange[] = []
state.doc.nodesBetween(from, to, (node, pos) => {
if (!node.isText) {
const relativeFrom = Math.max(from, pos)
const relativeTo = Math.min(to, pos + node.nodeSize)
nodeRanges = [...nodeRanges, {
nodeRanges.push({
node,
from: relativeFrom,
to: relativeTo,
}]
})
}
})