FIX: toolbar generating invalid multi-paragraph spoilers

FIX: toolbar generating invalid multi-paragraph spoilers

Toolbar will now enforce block mode when selected text is multiline:

Instead of this:

[spoiler]It is still

an issue[/spoiler]

toolbar will now inject this:

[spoiler]
It is still

an issue
[/spoiler]
diff --git a/assets/javascripts/initializers/spoiler-alert.js.es6 b/assets/javascripts/initializers/spoiler-alert.js.es6
index 11870cb..9cdc10e 100644
--- a/assets/javascripts/initializers/spoiler-alert.js.es6
+++ b/assets/javascripts/initializers/spoiler-alert.js.es6
@@ -27,7 +27,7 @@ function initializeSpoiler(api) {
           "[spoiler]",
           "[/spoiler]",
           "spoiler_text",
-          { multiline: false }
+          { multiline: false, useBlockMode: true }
         );
       }
     }
diff --git a/test/javascripts/acceptance/spoiler-button-test.js.es6 b/test/javascripts/acceptance/spoiler-button-test.js.es6
index d7d7e38..99bbe00 100644
--- a/test/javascripts/acceptance/spoiler-button-test.js.es6
+++ b/test/javascripts/acceptance/spoiler-button-test.js.es6
@@ -113,4 +113,30 @@ test("spoiler button", async assert => {
     30,
     "it should end highlighting at the right position"
   );
+
+  // enforce block mode when selected text is multiline
+  await fillIn(".d-editor-input", "Before\nthis is\n\nhidden\nAfter");
+
+  textarea.selectionStart = 7;
+  textarea.selectionEnd = 22;
+
+  await popUpMenu.expand();
+  await popUpMenu.selectRowByValue("insertSpoiler");
+
+  assert.equal(
+    find(".d-editor-input").val(),
+    `Before\n[spoiler]\nthis is\n\nhidden\n[/spoiler]\nAfter`,
+    "it should contain the right output"
+  );
+
+  assert.equal(
+    textarea.selectionStart,
+    17,
+    "it should start highlighting at the right position"
+  );
+  assert.equal(
+    textarea.selectionEnd,
+    32,
+    "it should end highlighting at the right position"
+  );
 });

GitHub sha: 2cac1b13

1 Like