ace2_inner: Use for..of iteration to improve readability
parent
f06307cb4c
commit
bc6428025a
|
@ -137,7 +137,7 @@ function Ace2Inner(editorInfo, cssManagers) {
|
||||||
'profileEnd',
|
'profileEnd',
|
||||||
];
|
];
|
||||||
console = {};
|
console = {};
|
||||||
for (let i = 0; i < names.length; ++i) console[names[i]] = noop;
|
for (const name of names) console[name] = noop;
|
||||||
}
|
}
|
||||||
|
|
||||||
const scheduler = parent; // hack for opera required
|
const scheduler = parent; // hack for opera required
|
||||||
|
@ -275,9 +275,9 @@ function Ace2Inner(editorInfo, cssManagers) {
|
||||||
applyChangesToBase: 1,
|
applyChangesToBase: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
hooks.callAll('aceRegisterNonScrollableEditEvents').forEach((eventType) => {
|
for (const eventType of hooks.callAll('aceRegisterNonScrollableEditEvents')) {
|
||||||
_nonScrollableEditEvents[eventType] = 1;
|
_nonScrollableEditEvents[eventType] = 1;
|
||||||
});
|
}
|
||||||
|
|
||||||
const isScrollableEditEvent = (eventType) => !_nonScrollableEditEvents[eventType];
|
const isScrollableEditEvent = (eventType) => !_nonScrollableEditEvents[eventType];
|
||||||
|
|
||||||
|
@ -987,9 +987,9 @@ function Ace2Inner(editorInfo, cssManagers) {
|
||||||
// inspired by Firefox bug #473255, where pasting formatted text
|
// inspired by Firefox bug #473255, where pasting formatted text
|
||||||
// causes the cursor to jump away, making the new HTML never found.
|
// causes the cursor to jump away, making the new HTML never found.
|
||||||
if (document.body.getElementsByTagName) {
|
if (document.body.getElementsByTagName) {
|
||||||
const nds = document.body.getElementsByTagName('style');
|
const elts = document.body.getElementsByTagName('style');
|
||||||
for (let i = 0; i < nds.length; i++) {
|
for (const elt of elts) {
|
||||||
const n = topLevel(nds[i]);
|
const n = topLevel(elt);
|
||||||
if (n && n.parentNode === document.body) {
|
if (n && n.parentNode === document.body) {
|
||||||
observeChangesAroundNode(n);
|
observeChangesAroundNode(n);
|
||||||
}
|
}
|
||||||
|
@ -1028,9 +1028,7 @@ function Ace2Inner(editorInfo, cssManagers) {
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
if (!dirtyRangesCheckOut) {
|
if (!dirtyRangesCheckOut) {
|
||||||
const numBodyNodes = document.body.childNodes.length;
|
for (const bodyNode of document.body.childNodes) {
|
||||||
for (let k = 0; k < numBodyNodes; k++) {
|
|
||||||
const bodyNode = document.body.childNodes.item(k);
|
|
||||||
if ((bodyNode.tagName) && ((!bodyNode.id) || (!rep.lines.containsKey(bodyNode.id)))) {
|
if ((bodyNode.tagName) && ((!bodyNode.id) || (!rep.lines.containsKey(bodyNode.id)))) {
|
||||||
observeChangesAroundNode(bodyNode);
|
observeChangesAroundNode(bodyNode);
|
||||||
}
|
}
|
||||||
|
@ -1106,17 +1104,14 @@ function Ace2Inner(editorInfo, cssManagers) {
|
||||||
|
|
||||||
const entries = [];
|
const entries = [];
|
||||||
const nodeToAddAfter = lastDirtyNode;
|
const nodeToAddAfter = lastDirtyNode;
|
||||||
const lineNodeInfos = new Array(lines.length);
|
const lineNodeInfos = [];
|
||||||
for (let k = 0; k < lines.length; k++) {
|
for (const lineString of lines) {
|
||||||
const lineString = lines[k];
|
|
||||||
const newEntry = createDomLineEntry(lineString);
|
const newEntry = createDomLineEntry(lineString);
|
||||||
entries.push(newEntry);
|
entries.push(newEntry);
|
||||||
lineNodeInfos[k] = newEntry.domInfo;
|
lineNodeInfos.push(newEntry.domInfo);
|
||||||
}
|
}
|
||||||
domInsertsNeeded.push([nodeToAddAfter, lineNodeInfos]);
|
domInsertsNeeded.push([nodeToAddAfter, lineNodeInfos]);
|
||||||
dirtyNodes.forEach((n) => {
|
for (const n of dirtyNodes) toDeleteAtEnd.push(n);
|
||||||
toDeleteAtEnd.push(n);
|
|
||||||
});
|
|
||||||
const spliceHints = {};
|
const spliceHints = {};
|
||||||
if (selStart) spliceHints.selStart = selStart;
|
if (selStart) spliceHints.selStart = selStart;
|
||||||
if (selEnd) spliceHints.selEnd = selEnd;
|
if (selEnd) spliceHints.selEnd = selEnd;
|
||||||
|
@ -1131,20 +1126,18 @@ function Ace2Inner(editorInfo, cssManagers) {
|
||||||
const domChanges = (splicesToDo.length > 0);
|
const domChanges = (splicesToDo.length > 0);
|
||||||
|
|
||||||
// update the representation
|
// update the representation
|
||||||
splicesToDo.forEach((splice) => {
|
for (const splice of splicesToDo) {
|
||||||
doIncorpLineSplice(splice[0], splice[1], splice[2], splice[3], splice[4]);
|
doIncorpLineSplice(splice[0], splice[1], splice[2], splice[3], splice[4]);
|
||||||
});
|
}
|
||||||
|
|
||||||
// do DOM inserts
|
// do DOM inserts
|
||||||
domInsertsNeeded.forEach((ins) => {
|
for (const ins of domInsertsNeeded) insertDomLines(ins[0], ins[1]);
|
||||||
insertDomLines(ins[0], ins[1]);
|
|
||||||
});
|
|
||||||
|
|
||||||
// delete old dom nodes
|
// delete old dom nodes
|
||||||
toDeleteAtEnd.forEach((n) => {
|
for (const n of toDeleteAtEnd) {
|
||||||
// parent of n may not be "root" in IE due to non-tree-shaped DOM (wtf)
|
// parent of n may not be "root" in IE due to non-tree-shaped DOM (wtf)
|
||||||
if (n.parentNode) n.parentNode.removeChild(n);
|
if (n.parentNode) n.parentNode.removeChild(n);
|
||||||
});
|
}
|
||||||
|
|
||||||
// needed to stop chrome from breaking the ui when long strings without spaces are pasted
|
// needed to stop chrome from breaking the ui when long strings without spaces are pasted
|
||||||
if (scrollToTheLeftNeeded) {
|
if (scrollToTheLeftNeeded) {
|
||||||
|
@ -1227,9 +1220,7 @@ function Ace2Inner(editorInfo, cssManagers) {
|
||||||
const insertDomLines = (nodeToAddAfter, infoStructs) => {
|
const insertDomLines = (nodeToAddAfter, infoStructs) => {
|
||||||
let lastEntry;
|
let lastEntry;
|
||||||
let lineStartOffset;
|
let lineStartOffset;
|
||||||
if (infoStructs.length < 1) return;
|
for (const info of infoStructs) {
|
||||||
|
|
||||||
infoStructs.forEach((info) => {
|
|
||||||
const node = info.node;
|
const node = info.node;
|
||||||
const key = uniqueId(node);
|
const key = uniqueId(node);
|
||||||
let entry;
|
let entry;
|
||||||
|
@ -1259,7 +1250,7 @@ function Ace2Inner(editorInfo, cssManagers) {
|
||||||
nodeToAddAfter = node;
|
nodeToAddAfter = node;
|
||||||
info.notifyAdded();
|
info.notifyAdded();
|
||||||
markNodeClean(node);
|
markNodeClean(node);
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const isCaret = () => (rep.selStart && rep.selEnd &&
|
const isCaret = () => (rep.selStart && rep.selEnd &&
|
||||||
|
@ -1422,10 +1413,10 @@ function Ace2Inner(editorInfo, cssManagers) {
|
||||||
|
|
||||||
insertDomLines(nodeToAddAfter, lineEntries.map((entry) => entry.domInfo));
|
insertDomLines(nodeToAddAfter, lineEntries.map((entry) => entry.domInfo));
|
||||||
|
|
||||||
keysToDelete.forEach((k) => {
|
for (const k of keysToDelete) {
|
||||||
const n = document.getElementById(k);
|
const n = document.getElementById(k);
|
||||||
n.parentNode.removeChild(n);
|
n.parentNode.removeChild(n);
|
||||||
});
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(rep.selStart &&
|
(rep.selStart &&
|
||||||
|
@ -1696,9 +1687,7 @@ function Ace2Inner(editorInfo, cssManagers) {
|
||||||
// Change the abstract representation of the document to have a different set of lines.
|
// Change the abstract representation of the document to have a different set of lines.
|
||||||
// Must be called after rep.alltext is set.
|
// Must be called after rep.alltext is set.
|
||||||
const doRepLineSplice = (startLine, deleteCount, newLineEntries) => {
|
const doRepLineSplice = (startLine, deleteCount, newLineEntries) => {
|
||||||
newLineEntries.forEach((entry) => {
|
for (const entry of newLineEntries) entry.width = entry.text.length + 1;
|
||||||
entry.width = entry.text.length + 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
const startOldChar = rep.lines.offsetOfIndex(startLine);
|
const startOldChar = rep.lines.offsetOfIndex(startLine);
|
||||||
const endOldChar = rep.lines.offsetOfIndex(startLine + deleteCount);
|
const endOldChar = rep.lines.offsetOfIndex(startLine + deleteCount);
|
||||||
|
@ -2074,11 +2063,11 @@ function Ace2Inner(editorInfo, cssManagers) {
|
||||||
const attribIsFormattingStyle = (attribName) => FORMATTING_STYLES.indexOf(attribName) !== -1;
|
const attribIsFormattingStyle = (attribName) => FORMATTING_STYLES.indexOf(attribName) !== -1;
|
||||||
|
|
||||||
const selectFormattingButtonIfLineHasStyleApplied = (rep) => {
|
const selectFormattingButtonIfLineHasStyleApplied = (rep) => {
|
||||||
FORMATTING_STYLES.forEach((style) => {
|
for (const style of FORMATTING_STYLES) {
|
||||||
const hasStyleOnRepSelection =
|
const hasStyleOnRepSelection =
|
||||||
documentAttributeManager.hasAttributeOnSelectionOrCaretPosition(style);
|
documentAttributeManager.hasAttributeOnSelectionOrCaretPosition(style);
|
||||||
updateStyleButtonState(style, hasStyleOnRepSelection);
|
updateStyleButtonState(style, hasStyleOnRepSelection);
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const doCreateDomLine =
|
const doCreateDomLine =
|
||||||
|
@ -2096,9 +2085,7 @@ function Ace2Inner(editorInfo, cssManagers) {
|
||||||
ul: 1,
|
ul: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
hooks.callAll('aceRegisterBlockElements').forEach((element) => {
|
for (const element of hooks.callAll('aceRegisterBlockElements')) _blockElems[element] = 1;
|
||||||
_blockElems[element] = 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
const isBlockElement = (n) => !!_blockElems[(n.tagName || '').toLowerCase()];
|
const isBlockElement = (n) => !!_blockElems[(n.tagName || '').toLowerCase()];
|
||||||
editorInfo.ace_isBlockElement = isBlockElement;
|
editorInfo.ace_isBlockElement = isBlockElement;
|
||||||
|
@ -2469,9 +2456,7 @@ function Ace2Inner(editorInfo, cssManagers) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mods.forEach((mod) => {
|
for (const mod of mods) setLineListType(mod[0], mod[1]);
|
||||||
setLineListType(mod[0], mod[1]);
|
|
||||||
});
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
editorInfo.ace_doIndentOutdent = doIndentOutdent;
|
editorInfo.ace_doIndentOutdent = doIndentOutdent;
|
||||||
|
@ -2689,8 +2674,8 @@ function Ace2Inner(editorInfo, cssManagers) {
|
||||||
// Known authors info, both current and historical
|
// Known authors info, both current and historical
|
||||||
const padAuthors = parent.parent.pad.userList();
|
const padAuthors = parent.parent.pad.userList();
|
||||||
let authorObj = {};
|
let authorObj = {};
|
||||||
authors.forEach((authorId) => {
|
for (const authorId of authors) {
|
||||||
padAuthors.forEach((padAuthor) => {
|
for (const padAuthor of padAuthors) {
|
||||||
// If the person doing the lookup is the author..
|
// If the person doing the lookup is the author..
|
||||||
if (padAuthor.userId === authorId) {
|
if (padAuthor.userId === authorId) {
|
||||||
if (parent.parent.clientVars.userId === authorId) {
|
if (parent.parent.clientVars.userId === authorId) {
|
||||||
|
@ -2701,15 +2686,15 @@ function Ace2Inner(editorInfo, cssManagers) {
|
||||||
authorObj = padAuthor;
|
authorObj = padAuthor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
if (!authorObj) {
|
if (!authorObj) {
|
||||||
author = 'Unknown';
|
author = 'Unknown';
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
author = authorObj.name;
|
author = authorObj.name;
|
||||||
if (!author) author = 'Unknown';
|
if (!author) author = 'Unknown';
|
||||||
authorNames.push(author);
|
authorNames.push(author);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
if (authors.length === 1) {
|
if (authors.length === 1) {
|
||||||
authorString = `The author of this line is ${authorNames[0]}`;
|
authorString = `The author of this line is ${authorNames[0]}`;
|
||||||
|
@ -3271,7 +3256,7 @@ function Ace2Inner(editorInfo, cssManagers) {
|
||||||
|
|
||||||
const _teardownActions = [];
|
const _teardownActions = [];
|
||||||
|
|
||||||
const teardown = () => _teardownActions.forEach((a) => a());
|
const teardown = () => { for (const a of _teardownActions) a(); };
|
||||||
|
|
||||||
let inInternationalComposition = null;
|
let inInternationalComposition = null;
|
||||||
editorInfo.ace_getInInternationalComposition = () => inInternationalComposition;
|
editorInfo.ace_getInInternationalComposition = () => inInternationalComposition;
|
||||||
|
@ -3501,9 +3486,7 @@ function Ace2Inner(editorInfo, cssManagers) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mods.forEach((mod) => {
|
for (const mod of mods) setLineListType(mod[0], mod[1]);
|
||||||
setLineListType(mod[0], mod[1]);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const doInsertUnorderedList = () => {
|
const doInsertUnorderedList = () => {
|
||||||
|
@ -3537,10 +3520,7 @@ function Ace2Inner(editorInfo, cssManagers) {
|
||||||
const innerdocbodyStyles = getComputedStyle(document.body);
|
const innerdocbodyStyles = getComputedStyle(document.body);
|
||||||
const defaultLineHeight = parseInt(innerdocbodyStyles['line-height']);
|
const defaultLineHeight = parseInt(innerdocbodyStyles['line-height']);
|
||||||
|
|
||||||
let docLine = document.body.firstElementChild;
|
for (const docLine of document.body.children) {
|
||||||
|
|
||||||
// First loop to calculate the heights from doc body
|
|
||||||
while (docLine) {
|
|
||||||
let h;
|
let h;
|
||||||
const nextDocLine = docLine.nextElementSibling;
|
const nextDocLine = docLine.nextElementSibling;
|
||||||
if (nextDocLine) {
|
if (nextDocLine) {
|
||||||
|
@ -3575,7 +3555,6 @@ function Ace2Inner(editorInfo, cssManagers) {
|
||||||
} else {
|
} else {
|
||||||
lineHeights.push(defaultLineHeight);
|
lineHeights.push(defaultLineHeight);
|
||||||
}
|
}
|
||||||
docLine = nextDocLine;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let newNumLines = rep.lines.length();
|
let newNumLines = rep.lines.length();
|
||||||
|
|
Loading…
Reference in New Issue