Sync the implementation of the number of paragraphs marked for removal
authorAlexander Ebert <ebert@woltlab.com>
Mon, 8 May 2023 14:33:26 +0000 (16:33 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 8 May 2023 16:34:04 +0000 (18:34 +0200)
ts/WoltLabSuite/Core/Component/Ckeditor/Cleanup.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Cleanup.js

index fee08a6a5e0eab9a0faa07c48cac7e875600bef2..cb7f75c273e5bf1be713cfdf4fde5a40fa7f33e2 100644 (file)
@@ -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) => {
index 3e0f18b1d0eed125f5b1f93f02d2db59e8904142..ccbe5f0a337abd92ec450d1eefd3be81ee5b456a 100644 (file)
@@ -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();