Invert conditions to improve readability

This commit is contained in:
Richard Hansen 2021-11-18 18:59:17 -05:00
parent cdad5c3325
commit 9e7b142bb7
3 changed files with 46 additions and 65 deletions

View file

@ -147,13 +147,10 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({
getAttributeOnLine(lineNum, attributeName) { getAttributeOnLine(lineNum, attributeName) {
// get `attributeName` attribute of first char of line // get `attributeName` attribute of first char of line
const aline = this.rep.alines[lineNum]; const aline = this.rep.alines[lineNum];
if (aline) { if (!aline) return '';
const opIter = Changeset.opIterator(aline); const opIter = Changeset.opIterator(aline);
if (opIter.hasNext()) { if (!opIter.hasNext()) return '';
return Changeset.opAttributeValue(opIter.next(), attributeName, this.rep.apool) || ''; return Changeset.opAttributeValue(opIter.next(), attributeName, this.rep.apool) || '';
}
}
return '';
}, },
/* /*
@ -163,21 +160,16 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({
getAttributesOnLine(lineNum) { getAttributesOnLine(lineNum) {
// get attributes of first char of line // get attributes of first char of line
const aline = this.rep.alines[lineNum]; const aline = this.rep.alines[lineNum];
const attributes = []; if (!aline) return [];
if (aline) {
const opIter = Changeset.opIterator(aline); const opIter = Changeset.opIterator(aline);
let op; if (!opIter.hasNext()) return [];
if (opIter.hasNext()) { const op = opIter.next();
op = opIter.next();
if (!op.attribs) return []; if (!op.attribs) return [];
const attributes = [];
Changeset.eachAttribNumber(op.attribs, (n) => { Changeset.eachAttribNumber(op.attribs, (n) => {
attributes.push([this.rep.apool.getAttribKey(n), this.rep.apool.getAttribValue(n)]); attributes.push([this.rep.apool.getAttribKey(n), this.rep.apool.getAttribValue(n)]);
}); });
return attributes; return attributes;
}
}
return [];
}, },
/* /*
@ -278,27 +270,22 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({
// we need to sum up how much characters each operations take until the wanted position // we need to sum up how much characters each operations take until the wanted position
let currentPointer = 0; let currentPointer = 0;
const attributes = [];
let currentOperation; let currentOperation;
while (opIter.hasNext()) { while (opIter.hasNext()) {
currentOperation = opIter.next(); currentOperation = opIter.next();
currentPointer += currentOperation.chars; currentPointer += currentOperation.chars;
if (currentPointer <= column) continue;
if (currentPointer > column) { const attributes = [];
// we got the operation of the wanted position, now collect all its attributes
Changeset.eachAttribNumber(currentOperation.attribs, (n) => { Changeset.eachAttribNumber(currentOperation.attribs, (n) => {
attributes.push([ attributes.push([
this.rep.apool.getAttribKey(n), this.rep.apool.getAttribKey(n),
this.rep.apool.getAttribValue(n), this.rep.apool.getAttribValue(n),
]); ]);
}); });
// skip the loop
return attributes; return attributes;
} }
} return [];
return attributes;
}, },
/* /*

View file

@ -119,15 +119,11 @@ const loadBroadcastJS = (socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, Bro
const alines = this.alines; const alines = this.alines;
for (let i = 0; i < alines.length; i++) { for (let i = 0; i < alines.length; i++) {
Changeset.eachAttribNumber(alines[i], (n) => { Changeset.eachAttribNumber(alines[i], (n) => {
if (!seenNums[n]) { if (seenNums[n]) return;
seenNums[n] = true; seenNums[n] = true;
if (this.apool.getAttribKey(n) === 'author') { if (this.apool.getAttribKey(n) !== 'author') return;
const a = this.apool.getAttribValue(n); const a = this.apool.getAttribValue(n);
if (a) { if (a) authors.push(a);
authors.push(a);
}
}
}
}); });
} }
authors.sort(); authors.sort();

View file

@ -77,9 +77,9 @@ linestylefilter.getLineStyleFilter = (lineLength, aline, textAndClassFunc, apool
Changeset.eachAttribNumber(attribs, (n) => { Changeset.eachAttribNumber(attribs, (n) => {
// Give us this attributes key // Give us this attributes key
const key = apool.getAttribKey(n); const key = apool.getAttribKey(n);
if (key) { if (!key) return;
const value = apool.getAttribValue(n); const value = apool.getAttribValue(n);
if (value) { if (!value) return;
if (!isLineAttribMarker && AttributeManager.lineAttributes.indexOf(key) >= 0) { if (!isLineAttribMarker && AttributeManager.lineAttributes.indexOf(key) >= 0) {
isLineAttribMarker = true; isLineAttribMarker = true;
} }
@ -96,8 +96,6 @@ linestylefilter.getLineStyleFilter = (lineLength, aline, textAndClassFunc, apool
const results = hooks.callAll('aceAttribsToClasses', {linestylefilter, key, value}); const results = hooks.callAll('aceAttribsToClasses', {linestylefilter, key, value});
classes += ` ${results.join(' ')}`; classes += ` ${results.join(' ')}`;
} }
}
}
}); });
if (isLineAttribMarker) classes += ` ${lineAttributeMarker}`; if (isLineAttribMarker) classes += ` ${lineAttributeMarker}`;