From c1926e6dd269b461bcd18f05c5e959d2abda406c Mon Sep 17 00:00:00 2001 From: Kyle Zhao Date: Mon, 6 Nov 2017 02:03:52 -0500 Subject: [PATCH] FIX: do not generate multiple detail blocks when the selected input (#5290) consists of multiple lines --- .../initializers/apply-details.js.es6 | 2 +- .../acceptance/details-button-test.js.es6 | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/plugins/discourse-details/assets/javascripts/initializers/apply-details.js.es6 b/plugins/discourse-details/assets/javascripts/initializers/apply-details.js.es6 index 222b76e2913..e357aa574c1 100644 --- a/plugins/discourse-details/assets/javascripts/initializers/apply-details.js.es6 +++ b/plugins/discourse-details/assets/javascripts/initializers/apply-details.js.es6 @@ -18,7 +18,7 @@ function initializeDetails(api) { "\n" + `[details="${I18n.t("composer.details_title")}"]` + "\n", "\n[/details]\n", "details_text", - { multiline: true } + { multiline: false } ); this.set('optionsVisible', false); } diff --git a/plugins/discourse-details/test/javascripts/acceptance/details-button-test.js.es6 b/plugins/discourse-details/test/javascripts/acceptance/details-button-test.js.es6 index 93ff83cc2ed..b0f25283ec5 100644 --- a/plugins/discourse-details/test/javascripts/acceptance/details-button-test.js.es6 +++ b/plugins/discourse-details/test/javascripts/acceptance/details-button-test.js.es6 @@ -90,3 +90,28 @@ test('details button', (assert) => { assert.equal(textarea.selectionEnd, 49, 'it should end highlighting at the right position'); }); }); + +test('details button surrounds all selected text in a single details block', (assert) => { + const multilineInput = 'first line\n\nsecond line\n\nthird line'; + + visit("/"); + click('#create-topic'); + fillIn('.d-editor-input', multilineInput); + + andThen(() => { + const textarea = findTextarea(); + textarea.selectionStart = 0; + textarea.selectionEnd = textarea.value.length; + }); + + click('button.options'); + click('.popup-menu .d-icon-caret-right'); + + andThen(() => { + assert.equal( + find(".d-editor-input").val(), + `\n[details="${I18n.t('composer.details_title')}"]\n${multilineInput}\n[/details]\n`, + 'it should contain the right output' + ); + }); +});