diff --git a/wax-prosemirror-utilities/src/document/DocumentHelpers.js b/wax-prosemirror-utilities/src/document/DocumentHelpers.js index 4c09afca6e4927f8300ed454913a56f0221b282d..b5b0f7b9eeeeb2302f0c116f53bed69ceba0f39e 100644 --- a/wax-prosemirror-utilities/src/document/DocumentHelpers.js +++ b/wax-prosemirror-utilities/src/document/DocumentHelpers.js @@ -38,9 +38,6 @@ const findFragmentedMark = (state, PMmark) => { selection: { $from, $to }, doc, } = state; - const fromPos = [$from.pos - 1, $from.pos]; - const toPos = [$to.pos, $to.pos + 1]; - let markFound; // const type = state.config.schema.marks.comment; // const mark = empty @@ -57,20 +54,21 @@ const findFragmentedMark = (state, PMmark) => { // // // return undefined; - for (let i = 0; i < fromPos.length; i++) { - doc.nodesBetween(fromPos[i], toPos[i], (node, from) => { - if (node.marks) { - const actualMark = node.marks.find(mark => mark.type === PMmark); - if (actualMark) { - markFound = { - from, - to: from + node.nodeSize, - attrs: actualMark.attrs, - }; - } + let markFound; + + doc.nodesBetween($from.pos - 1, $to.pos, (node, from) => { + if (node.marks) { + const actualMark = node.marks.find(mark => mark.type === PMmark); + if (actualMark) { + markFound = { + from, + to: from + node.nodeSize, + attrs: actualMark.attrs, + }; } - }); - } + } + }); + return markFound; };