1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-30 18:39:51 +02:00

add change method to remove all marks from node by key (#1307)

* add change method to remove all marks from node by key

* handle text node in removeAllMarksByKey
This commit is contained in:
Ch1ll0ut1
2017-10-30 23:55:51 +07:00
committed by Ian Storm Taylor
parent 49ebbf9595
commit 0dc1f3d06e

View File

@@ -280,6 +280,28 @@ Changes.removeMarkByKey = (change, key, offset, length, mark, options = {}) => {
}
}
/**
* Remove all `marks` from node by `key`.
*
* @param {Change} change
* @param {String} key
* @param {Object} options
* @property {Boolean} normalize
*/
Changes.removeAllMarksByKey = (change, key, options = {}) => {
const { state } = change
const { document } = state
const node = document.getNode(key)
const texts = node.kind === 'text' ? [node] : node.getTextsAsArray()
texts.forEach((text) => {
text.getMarksAsArray().forEach((mark) => {
change.removeMarkByKey(text.key, 0, text.text.length, mark, options)
})
})
}
/**
* Remove a node by `key`.
*