From 0dc1f3d06eb3578cbf20b6bbe5f38513f3b89e81 Mon Sep 17 00:00:00 2001 From: Ch1ll0ut1 Date: Mon, 30 Oct 2017 23:55:51 +0700 Subject: [PATCH] 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 --- packages/slate/src/changes/by-key.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/slate/src/changes/by-key.js b/packages/slate/src/changes/by-key.js index 5d1b8b1a9..0d149f99c 100644 --- a/packages/slate/src/changes/by-key.js +++ b/packages/slate/src/changes/by-key.js @@ -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`. *