1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-27 17:09:53 +02:00

fix *ByTypeAsArray node methods to always return arrays

This commit is contained in:
Ian Storm Taylor
2017-05-09 22:28:39 -07:00
parent cb03f02d68
commit 12bbb630e1

View File

@@ -280,9 +280,14 @@ const Node = {
getBlocksByTypeAsArray(type) { getBlocksByTypeAsArray(type) {
return this.nodes.reduce((array, node) => { return this.nodes.reduce((array, node) => {
if (node.kind != 'block') return array if (node.kind != 'block') {
if (node.isLeafBlock() && node.type == type) return array.push(node) return array
return array.concat(node.getBlocksByTypeAsArray(type)) } else if (node.isLeafBlock() && node.type == type) {
array.push(node)
return array
} else {
return array.concat(node.getBlocksByTypeAsArray(type))
}
}, []) }, [])
}, },
@@ -766,9 +771,14 @@ const Node = {
getInlinesByTypeAsArray(type) { getInlinesByTypeAsArray(type) {
return this.nodes.reduce((inlines, node) => { return this.nodes.reduce((inlines, node) => {
if (node.kind == 'text') return inlines if (node.kind == 'text') {
if (node.isLeafInline() && node.type == type) return inlines.push(node) return inlines
return inlines.concat(node.getInlinesByTypeAsArray(type)) } else if (node.isLeafInline() && node.type == type) {
inlines.push(node)
return inlines
} else {
return inlines.concat(node.getInlinesByTypeAsArray(type))
}
}, []) }, [])
}, },