From c3dd207d8913797c88b7709b9e5785cc588ff0ea Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 8 May 2023 16:33:26 +0200 Subject: [PATCH] Sync the implementation of the number of paragraphs marked for removal --- ts/WoltLabSuite/Core/Component/Ckeditor/Cleanup.ts | 11 ++--------- .../WoltLabSuite/Core/Component/Ckeditor/Cleanup.js | 11 ++--------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/ts/WoltLabSuite/Core/Component/Ckeditor/Cleanup.ts b/ts/WoltLabSuite/Core/Component/Ckeditor/Cleanup.ts index fee08a6a5e..cb7f75c273 100644 --- a/ts/WoltLabSuite/Core/Component/Ckeditor/Cleanup.ts +++ b/ts/WoltLabSuite/Core/Component/Ckeditor/Cleanup.ts @@ -105,18 +105,11 @@ function reduceSpacerParagraphs(paragraphs: HTMLParagraphElement[]): void { // can safely remove it. candidate.remove(); } else { - let numberOfParagraphsToRemove: number; - // We need to reduce the number of paragraphs by half, unless it // is an uneven number in which case we need to remove one // additional paragraph. - if (offset % 2 === 1) { - // 2 -> 1, 4 -> 2 - numberOfParagraphsToRemove = Math.ceil(offset / 2); - } else { - // 3 -> 1, 5 -> 2 - numberOfParagraphsToRemove = Math.ceil(offset / 2) + 1; - } + const totalNumberOfParagraphs = offset + 1; + const numberOfParagraphsToRemove = Math.ceil(totalNumberOfParagraphs / 2); const removeParagraphs = paragraphs.slice(i, i + numberOfParagraphsToRemove); removeParagraphs.forEach((paragraph) => { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Cleanup.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Cleanup.js index 3e0f18b1d0..ccbe5f0a33 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Cleanup.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Cleanup.js @@ -93,18 +93,11 @@ define(["require", "exports", "tslib", "../../Dom/Util"], function (require, exp candidate.remove(); } else { - let numberOfParagraphsToRemove; // We need to reduce the number of paragraphs by half, unless it // is an uneven number in which case we need to remove one // additional paragraph. - if (offset % 2 === 1) { - // 2 -> 1, 4 -> 2 - numberOfParagraphsToRemove = Math.ceil(offset / 2); - } - else { - // 3 -> 1, 5 -> 2 - numberOfParagraphsToRemove = Math.ceil(offset / 2) + 1; - } + const totalNumberOfParagraphs = offset + 1; + const numberOfParagraphsToRemove = Math.ceil(totalNumberOfParagraphs / 2); const removeParagraphs = paragraphs.slice(i, i + numberOfParagraphsToRemove); removeParagraphs.forEach((paragraph) => { paragraph.remove(); -- 2.20.1