mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-23 17:06:16 -04:00
Invert conditions to improve readability
This commit is contained in:
parent
cdad5c3325
commit
9e7b142bb7
3 changed files with 46 additions and 65 deletions
|
@ -147,13 +147,10 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({
|
|||
getAttributeOnLine(lineNum, attributeName) {
|
||||
// get `attributeName` attribute of first char of line
|
||||
const aline = this.rep.alines[lineNum];
|
||||
if (aline) {
|
||||
const opIter = Changeset.opIterator(aline);
|
||||
if (opIter.hasNext()) {
|
||||
return Changeset.opAttributeValue(opIter.next(), attributeName, this.rep.apool) || '';
|
||||
}
|
||||
}
|
||||
return '';
|
||||
if (!aline) return '';
|
||||
const opIter = Changeset.opIterator(aline);
|
||||
if (!opIter.hasNext()) return '';
|
||||
return Changeset.opAttributeValue(opIter.next(), attributeName, this.rep.apool) || '';
|
||||
},
|
||||
|
||||
/*
|
||||
|
@ -163,21 +160,16 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({
|
|||
getAttributesOnLine(lineNum) {
|
||||
// get attributes of first char of line
|
||||
const aline = this.rep.alines[lineNum];
|
||||
if (!aline) return [];
|
||||
const opIter = Changeset.opIterator(aline);
|
||||
if (!opIter.hasNext()) return [];
|
||||
const op = opIter.next();
|
||||
if (!op.attribs) return [];
|
||||
const attributes = [];
|
||||
if (aline) {
|
||||
const opIter = Changeset.opIterator(aline);
|
||||
let op;
|
||||
if (opIter.hasNext()) {
|
||||
op = opIter.next();
|
||||
if (!op.attribs) return [];
|
||||
|
||||
Changeset.eachAttribNumber(op.attribs, (n) => {
|
||||
attributes.push([this.rep.apool.getAttribKey(n), this.rep.apool.getAttribValue(n)]);
|
||||
});
|
||||
return attributes;
|
||||
}
|
||||
}
|
||||
return [];
|
||||
Changeset.eachAttribNumber(op.attribs, (n) => {
|
||||
attributes.push([this.rep.apool.getAttribKey(n), this.rep.apool.getAttribValue(n)]);
|
||||
});
|
||||
return attributes;
|
||||
},
|
||||
|
||||
/*
|
||||
|
@ -278,27 +270,22 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({
|
|||
|
||||
// we need to sum up how much characters each operations take until the wanted position
|
||||
let currentPointer = 0;
|
||||
const attributes = [];
|
||||
let currentOperation;
|
||||
|
||||
while (opIter.hasNext()) {
|
||||
currentOperation = opIter.next();
|
||||
currentPointer += currentOperation.chars;
|
||||
|
||||
if (currentPointer > column) {
|
||||
// we got the operation of the wanted position, now collect all its attributes
|
||||
Changeset.eachAttribNumber(currentOperation.attribs, (n) => {
|
||||
attributes.push([
|
||||
this.rep.apool.getAttribKey(n),
|
||||
this.rep.apool.getAttribValue(n),
|
||||
]);
|
||||
});
|
||||
|
||||
// skip the loop
|
||||
return attributes;
|
||||
}
|
||||
if (currentPointer <= column) continue;
|
||||
const attributes = [];
|
||||
Changeset.eachAttribNumber(currentOperation.attribs, (n) => {
|
||||
attributes.push([
|
||||
this.rep.apool.getAttribKey(n),
|
||||
this.rep.apool.getAttribValue(n),
|
||||
]);
|
||||
});
|
||||
return attributes;
|
||||
}
|
||||
return attributes;
|
||||
return [];
|
||||
},
|
||||
|
||||
/*
|
||||
|
|
|
@ -119,15 +119,11 @@ const loadBroadcastJS = (socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, Bro
|
|||
const alines = this.alines;
|
||||
for (let i = 0; i < alines.length; i++) {
|
||||
Changeset.eachAttribNumber(alines[i], (n) => {
|
||||
if (!seenNums[n]) {
|
||||
seenNums[n] = true;
|
||||
if (this.apool.getAttribKey(n) === 'author') {
|
||||
const a = this.apool.getAttribValue(n);
|
||||
if (a) {
|
||||
authors.push(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (seenNums[n]) return;
|
||||
seenNums[n] = true;
|
||||
if (this.apool.getAttribKey(n) !== 'author') return;
|
||||
const a = this.apool.getAttribValue(n);
|
||||
if (a) authors.push(a);
|
||||
});
|
||||
}
|
||||
authors.sort();
|
||||
|
|
|
@ -77,26 +77,24 @@ linestylefilter.getLineStyleFilter = (lineLength, aline, textAndClassFunc, apool
|
|||
Changeset.eachAttribNumber(attribs, (n) => {
|
||||
// Give us this attributes key
|
||||
const key = apool.getAttribKey(n);
|
||||
if (key) {
|
||||
const value = apool.getAttribValue(n);
|
||||
if (value) {
|
||||
if (!isLineAttribMarker && AttributeManager.lineAttributes.indexOf(key) >= 0) {
|
||||
isLineAttribMarker = true;
|
||||
}
|
||||
if (key === 'author') {
|
||||
classes += ` ${linestylefilter.getAuthorClassName(value)}`;
|
||||
} else if (key === 'list') {
|
||||
classes += ` list:${value}`;
|
||||
} else if (key === 'start') {
|
||||
// Needed to introduce the correct Ordered list item start number on import
|
||||
classes += ` start:${value}`;
|
||||
} else if (linestylefilter.ATTRIB_CLASSES[key]) {
|
||||
classes += ` ${linestylefilter.ATTRIB_CLASSES[key]}`;
|
||||
} else {
|
||||
const results = hooks.callAll('aceAttribsToClasses', {linestylefilter, key, value});
|
||||
classes += ` ${results.join(' ')}`;
|
||||
}
|
||||
}
|
||||
if (!key) return;
|
||||
const value = apool.getAttribValue(n);
|
||||
if (!value) return;
|
||||
if (!isLineAttribMarker && AttributeManager.lineAttributes.indexOf(key) >= 0) {
|
||||
isLineAttribMarker = true;
|
||||
}
|
||||
if (key === 'author') {
|
||||
classes += ` ${linestylefilter.getAuthorClassName(value)}`;
|
||||
} else if (key === 'list') {
|
||||
classes += ` list:${value}`;
|
||||
} else if (key === 'start') {
|
||||
// Needed to introduce the correct Ordered list item start number on import
|
||||
classes += ` start:${value}`;
|
||||
} else if (linestylefilter.ATTRIB_CLASSES[key]) {
|
||||
classes += ` ${linestylefilter.ATTRIB_CLASSES[key]}`;
|
||||
} else {
|
||||
const results = hooks.callAll('aceAttribsToClasses', {linestylefilter, key, value});
|
||||
classes += ` ${results.join(' ')}`;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue