mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 07:56:16 -04:00
Changeset: Use for...of
iteration to improve readability
This commit is contained in:
parent
6d5b737140
commit
1cad5d881a
1 changed files with 10 additions and 22 deletions
|
@ -1146,9 +1146,9 @@ exports.composeAttributes = (att1, att2, resultIsMutation, pool) => {
|
||||||
});
|
});
|
||||||
atts.sort();
|
atts.sort();
|
||||||
const buf = exports.stringAssembler();
|
const buf = exports.stringAssembler();
|
||||||
for (let i = 0; i < atts.length; i++) {
|
for (const att of atts) {
|
||||||
buf.append('*');
|
buf.append('*');
|
||||||
buf.append(exports.numToString(pool.putAttrib(atts[i])));
|
buf.append(exports.numToString(pool.putAttrib(att)));
|
||||||
}
|
}
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
};
|
};
|
||||||
|
@ -1306,8 +1306,7 @@ exports.mutateAttributionLines = (cs, lines, pool) => {
|
||||||
*/
|
*/
|
||||||
exports.joinAttributionLines = (theAlines) => {
|
exports.joinAttributionLines = (theAlines) => {
|
||||||
const assem = exports.mergingOpAssembler();
|
const assem = exports.mergingOpAssembler();
|
||||||
for (let i = 0; i < theAlines.length; i++) {
|
for (const aline of theAlines) {
|
||||||
const aline = theAlines[i];
|
|
||||||
const iter = exports.opIterator(aline);
|
const iter = exports.opIterator(aline);
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
assem.append(iter.next());
|
assem.append(iter.next());
|
||||||
|
@ -1507,10 +1506,8 @@ const toSplices = (cs) => {
|
||||||
exports.characterRangeFollow = (cs, startChar, endChar, insertionsAfter) => {
|
exports.characterRangeFollow = (cs, startChar, endChar, insertionsAfter) => {
|
||||||
let newStartChar = startChar;
|
let newStartChar = startChar;
|
||||||
let newEndChar = endChar;
|
let newEndChar = endChar;
|
||||||
const splices = toSplices(cs);
|
|
||||||
let lengthChangeSoFar = 0;
|
let lengthChangeSoFar = 0;
|
||||||
for (let i = 0; i < splices.length; i++) {
|
for (const splice of toSplices(cs)) {
|
||||||
const splice = splices[i];
|
|
||||||
const spliceStart = splice[0] + lengthChangeSoFar;
|
const spliceStart = splice[0] + lengthChangeSoFar;
|
||||||
const spliceEnd = splice[1] + lengthChangeSoFar;
|
const spliceEnd = splice[1] + lengthChangeSoFar;
|
||||||
const newTextLength = splice[2].length;
|
const newTextLength = splice[2].length;
|
||||||
|
@ -1906,8 +1903,7 @@ exports.makeAttribsString = (opcode, attribs, pool) => {
|
||||||
attribs.sort();
|
attribs.sort();
|
||||||
}
|
}
|
||||||
const result = [];
|
const result = [];
|
||||||
for (let i = 0; i < attribs.length; i++) {
|
for (const pair of attribs) {
|
||||||
const pair = attribs[i];
|
|
||||||
if (opcode === '=' || (opcode === '+' && pair[1])) {
|
if (opcode === '=' || (opcode === '+' && pair[1])) {
|
||||||
result.push(`*${exports.numToString(pool.putAttrib(pair))}`);
|
result.push(`*${exports.numToString(pool.putAttrib(pair))}`);
|
||||||
}
|
}
|
||||||
|
@ -2072,23 +2068,15 @@ exports.inverse = (cs, lines, alines, pool) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const attribKeys = [];
|
|
||||||
const attribValues = [];
|
|
||||||
while (csIter.hasNext()) {
|
while (csIter.hasNext()) {
|
||||||
const csOp = csIter.next();
|
const csOp = csIter.next();
|
||||||
if (csOp.opcode === '=') {
|
if (csOp.opcode === '=') {
|
||||||
if (csOp.attribs) {
|
if (csOp.attribs) {
|
||||||
attribKeys.length = 0;
|
const csAttribs = [];
|
||||||
attribValues.length = 0;
|
exports.eachAttribNumber(csOp.attribs, (n) => csAttribs.push(pool.getAttrib(n)));
|
||||||
exports.eachAttribNumber(csOp.attribs, (n) => {
|
|
||||||
attribKeys.push(pool.getAttribKey(n));
|
|
||||||
attribValues.push(pool.getAttribValue(n));
|
|
||||||
});
|
|
||||||
const undoBackToAttribs = cachedStrFunc((attribs) => {
|
const undoBackToAttribs = cachedStrFunc((attribs) => {
|
||||||
const backAttribs = [];
|
const backAttribs = [];
|
||||||
for (let i = 0; i < attribKeys.length; i++) {
|
for (const [appliedKey, appliedValue] of csAttribs) {
|
||||||
const appliedKey = attribKeys[i];
|
|
||||||
const appliedValue = attribValues[i];
|
|
||||||
const oldValue = exports.attribsAttributeValue(attribs, appliedKey, pool);
|
const oldValue = exports.attribsAttributeValue(attribs, appliedKey, pool);
|
||||||
if (appliedValue !== oldValue) {
|
if (appliedValue !== oldValue) {
|
||||||
backAttribs.push([appliedKey, oldValue]);
|
backAttribs.push([appliedKey, oldValue]);
|
||||||
|
@ -2289,9 +2277,9 @@ const followAttributes = (att1, att2, pool) => {
|
||||||
});
|
});
|
||||||
// we've only removed attributes, so they're already sorted
|
// we've only removed attributes, so they're already sorted
|
||||||
const buf = exports.stringAssembler();
|
const buf = exports.stringAssembler();
|
||||||
for (let i = 0; i < atts.length; i++) {
|
for (const att of atts) {
|
||||||
buf.append('*');
|
buf.append('*');
|
||||||
buf.append(exports.numToString(pool.putAttrib(atts[i])));
|
buf.append(exports.numToString(pool.putAttrib(att)));
|
||||||
}
|
}
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue