Editor: better async adding of sections in initWithStyle
This commit is contained in:
parent
fa6b0f4477
commit
5caab7ab47
17
edit.js
17
edit.js
|
@ -925,11 +925,20 @@ function initWithStyle(style) {
|
|||
document.querySelectorAll("#sections > div").forEach(function(div) {
|
||||
div.parentNode.removeChild(div);
|
||||
});
|
||||
(style.sections.length == 0 ? [{code: ""}] : style.sections).forEach(function(section) {
|
||||
setTimeout(function() {
|
||||
maximizeCodeHeight(addSection(null, section), editors.length == style.sections.length);
|
||||
var queue = style.sections.length ? style.sections : [{code: ""}];
|
||||
var queueStart = new Date().getTime();
|
||||
// after 200ms the sections will be added asynchronously
|
||||
while (new Date().getTime() - queueStart <= 200 && queue.length) {
|
||||
maximizeCodeHeight(addSection(null, queue.shift()), !queue.length);
|
||||
}
|
||||
if (queue.length) {
|
||||
setTimeout(function processQueue() {
|
||||
maximizeCodeHeight(addSection(null, queue.shift()), !queue.length);
|
||||
if (queue.length) {
|
||||
setTimeout(processQueue, 0);
|
||||
}
|
||||
}, 0);
|
||||
});
|
||||
}
|
||||
initHooks();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user