mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-20 06:01:24 +02:00
Add method to return all keys in a node
This commit is contained in:
@@ -20,6 +20,22 @@ import { List, Set } from 'immutable'
|
|||||||
|
|
||||||
const Node = {
|
const Node = {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a set of all keys in the node.
|
||||||
|
*
|
||||||
|
* @return {Set<Node>} keys
|
||||||
|
*/
|
||||||
|
|
||||||
|
getKeys() {
|
||||||
|
const keys = []
|
||||||
|
|
||||||
|
this.filterDescendants(desc => {
|
||||||
|
keys.push(desc.key)
|
||||||
|
})
|
||||||
|
|
||||||
|
return Set(keys)
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assert that a node has a child by `key` and return it.
|
* Assert that a node has a child by `key` and return it.
|
||||||
*
|
*
|
||||||
@@ -1044,11 +1060,7 @@ const Node = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
insertNode(index, node) {
|
insertNode(index, node) {
|
||||||
let keys = new Set([ this.key ])
|
let keys = this.getKeys()
|
||||||
|
|
||||||
this.findDescendant((desc) => {
|
|
||||||
keys = keys.add(desc.key)
|
|
||||||
})
|
|
||||||
|
|
||||||
if (keys.contains(node.key)) {
|
if (keys.contains(node.key)) {
|
||||||
node = node.regenerateKey()
|
node = node.regenerateKey()
|
||||||
|
Reference in New Issue
Block a user