From 50dce085c297e3c5f3c03f41a50eef52327cc1d5 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Mon, 15 Nov 2021 14:18:04 -0500 Subject: [PATCH] ImportHtml: In-line an unnecessary function --- src/node/utils/ImportHtml.js | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/node/utils/ImportHtml.js b/src/node/utils/ImportHtml.js index cc3ecb09b..807dab536 100644 --- a/src/node/utils/ImportHtml.js +++ b/src/node/utils/ImportHtml.js @@ -66,28 +66,24 @@ exports.setPadHTML = async (pad, html) => { apiLogger.debug(newText); const newAttribs = `${result.lineAttribs.join('|1+1')}|1+1`; - const eachAttribRun = (attribs, func /* (startInNewText, endInNewText, attribs)*/) => { - const attribsIter = Changeset.opIterator(attribs); - let textIndex = 0; - const newTextStart = 0; - const newTextEnd = newText.length; - while (attribsIter.hasNext()) { - const op = attribsIter.next(); - const nextIndex = textIndex + op.chars; - if (!(nextIndex <= newTextStart || textIndex >= newTextEnd)) { - func(Math.max(newTextStart, textIndex), Math.min(newTextEnd, nextIndex), op.attribs); - } - textIndex = nextIndex; - } - }; - // create a new changeset with a helper builder object const builder = Changeset.builder(1); // assemble each line into the builder - eachAttribRun(newAttribs, (start, end, attribs) => { - builder.insert(newText.substring(start, end), attribs); - }); + const attribsIter = Changeset.opIterator(newAttribs); + let textIndex = 0; + const newTextStart = 0; + const newTextEnd = newText.length; + while (attribsIter.hasNext()) { + const op = attribsIter.next(); + const nextIndex = textIndex + op.chars; + if (!(nextIndex <= newTextStart || textIndex >= newTextEnd)) { + const start = Math.max(newTextStart, textIndex); + const end = Math.min(newTextEnd, nextIndex); + builder.insert(newText.substring(start, end), op.attribs); + } + textIndex = nextIndex; + } // the changeset is ready! const theChangeset = builder.toString();