From fde547c3a83215042f11505bf98e437c6e0f67e7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 5 Jan 2021 16:03:28 +0100 Subject: [PATCH] Make CHUNK_SIZE a static class member in `Core/Bbcode/Code` --- .../install/files/js/WoltLabSuite/Core/Bbcode/Code.js | 6 +++--- .../install/files/ts/WoltLabSuite/Core/Bbcode/Code.ts | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Bbcode/Code.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Bbcode/Code.js index 63ebb5ceed..c2c881189d 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Bbcode/Code.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Bbcode/Code.js @@ -14,7 +14,6 @@ define(["require", "exports", "tslib", "../Language", "../Clipboard", "../Ui/Not Prism_1 = tslib_1.__importDefault(Prism_1); PrismHelper = tslib_1.__importStar(PrismHelper); prism_meta_1 = tslib_1.__importDefault(prism_meta_1); - const CHUNK_SIZE = 50; async function waitForIdle() { return new Promise((resolve, _reject) => { if (window.requestIdleCallback) { @@ -82,9 +81,9 @@ define(["require", "exports", "tslib", "../Language", "../Clipboard", "../Ui/Not await waitForIdle(); const originalLines = this.codeContainer.querySelectorAll(".codeBoxLine > span"); const highlightedLines = PrismHelper.splitIntoLines(container); - for (let chunkStart = 0, max = originalLines.length; chunkStart < max; chunkStart += CHUNK_SIZE) { + for (let chunkStart = 0, max = originalLines.length; chunkStart < max; chunkStart += Code.chunkSize) { await waitForIdle(); - const chunkEnd = Math.min(chunkStart + CHUNK_SIZE, max); + const chunkEnd = Math.min(chunkStart + Code.chunkSize, max); for (let offset = chunkStart; offset < chunkEnd; offset++) { const toReplace = originalLines[offset]; const replacement = highlightedLines.next().value; @@ -95,5 +94,6 @@ define(["require", "exports", "tslib", "../Language", "../Clipboard", "../Ui/Not this.container.classList.add("highlighted"); } } + Code.chunkSize = 50; return Code; }); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Bbcode/Code.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Bbcode/Code.ts index b6b25bd92a..a05d4a2d85 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Bbcode/Code.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Bbcode/Code.ts @@ -14,8 +14,6 @@ import Prism from "../Prism"; import * as PrismHelper from "../Prism/Helper"; import PrismMeta from "../prism-meta"; -const CHUNK_SIZE = 50; - async function waitForIdle(): Promise { return new Promise((resolve, _reject) => { if ((window as any).requestIdleCallback) { @@ -27,6 +25,8 @@ async function waitForIdle(): Promise { } class Code { + private static readonly chunkSize = 50; + private readonly container: HTMLElement; private codeContainer: HTMLElement; private language: string | undefined; @@ -105,10 +105,10 @@ class Code { const originalLines = this.codeContainer.querySelectorAll(".codeBoxLine > span"); const highlightedLines = PrismHelper.splitIntoLines(container); - for (let chunkStart = 0, max = originalLines.length; chunkStart < max; chunkStart += CHUNK_SIZE) { + for (let chunkStart = 0, max = originalLines.length; chunkStart < max; chunkStart += Code.chunkSize) { await waitForIdle(); - const chunkEnd = Math.min(chunkStart + CHUNK_SIZE, max); + const chunkEnd = Math.min(chunkStart + Code.chunkSize, max); for (let offset = chunkStart; offset < chunkEnd; offset++) { const toReplace = originalLines[offset]!; -- 2.20.1