ImportHtml: In-line an unnecessary function
parent
afdb01681a
commit
50dce085c2
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue