Scaffold: Improve perceived translation speed

When translators do a lot of logging.

https://github.com/zotero/translators/pull/3022#issuecomment-1517291971
This commit is contained in:
Abe Jellinek 2023-04-21 13:38:04 -04:00
parent fb2d35c765
commit c07eccb468

View file

@ -1170,13 +1170,19 @@ var Scaffold = new function () {
string = fix2028(Zotero.Utilities.varDump(string));
}
if (output.value) output.value += "\n";
output.value += Zotero.Utilities.lpad(date.getHours(), '0', 2)
// Put off actually building the log message and appending it to the console until the next animation frame
// so as not to slow down translation with repeated layout recalculations triggered by appending text
// and accessing scrollHeight
// requestAnimationFrame() callbacks are guaranteed to be called in the order they were set
requestAnimationFrame(() => {
if (output.value) output.value += "\n";
output.value += Zotero.Utilities.lpad(date.getHours(), '0', 2)
+ ":" + Zotero.Utilities.lpad(date.getMinutes(), '0', 2)
+ ":" + Zotero.Utilities.lpad(date.getSeconds(), '0', 2)
+ " " + string.replace(/\n/g, "\n ");
// move to end
output.scrollTop = output.scrollHeight;
// move to end
output.scrollTop = output.scrollHeight;
});
}
/*