mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 16: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) {
|
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];
|
||||||
|
if (!aline) return [];
|
||||||
|
const opIter = Changeset.opIterator(aline);
|
||||||
|
if (!opIter.hasNext()) return [];
|
||||||
|
const op = opIter.next();
|
||||||
|
if (!op.attribs) return [];
|
||||||
const attributes = [];
|
const attributes = [];
|
||||||
if (aline) {
|
Changeset.eachAttribNumber(op.attribs, (n) => {
|
||||||
const opIter = Changeset.opIterator(aline);
|
attributes.push([this.rep.apool.getAttribKey(n), this.rep.apool.getAttribValue(n)]);
|
||||||
let op;
|
});
|
||||||
if (opIter.hasNext()) {
|
return attributes;
|
||||||
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 [];
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -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),
|
]);
|
||||||
]);
|
});
|
||||||
});
|
return attributes;
|
||||||
|
|
||||||
// skip the loop
|
|
||||||
return attributes;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return attributes;
|
return [];
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -77,26 +77,24 @@ 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;
|
||||||
}
|
}
|
||||||
if (key === 'author') {
|
if (key === 'author') {
|
||||||
classes += ` ${linestylefilter.getAuthorClassName(value)}`;
|
classes += ` ${linestylefilter.getAuthorClassName(value)}`;
|
||||||
} else if (key === 'list') {
|
} else if (key === 'list') {
|
||||||
classes += ` list:${value}`;
|
classes += ` list:${value}`;
|
||||||
} else if (key === 'start') {
|
} else if (key === 'start') {
|
||||||
// Needed to introduce the correct Ordered list item start number on import
|
// Needed to introduce the correct Ordered list item start number on import
|
||||||
classes += ` start:${value}`;
|
classes += ` start:${value}`;
|
||||||
} else if (linestylefilter.ATTRIB_CLASSES[key]) {
|
} else if (linestylefilter.ATTRIB_CLASSES[key]) {
|
||||||
classes += ` ${linestylefilter.ATTRIB_CLASSES[key]}`;
|
classes += ` ${linestylefilter.ATTRIB_CLASSES[key]}`;
|
||||||
} else {
|
} else {
|
||||||
const results = hooks.callAll('aceAttribsToClasses', {linestylefilter, key, value});
|
const results = hooks.callAll('aceAttribsToClasses', {linestylefilter, key, value});
|
||||||
classes += ` ${results.join(' ')}`;
|
classes += ` ${results.join(' ')}`;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue