ImportHtml: In-line an unnecessary function

pull/5285/head
Richard Hansen 2021-11-15 14:18:04 -05:00
parent afdb01681a
commit 50dce085c2
1 changed files with 14 additions and 18 deletions

View File

@ -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();