From 64e1ca6daa54d02ac01fb893008a2ec1e9b6fc8c Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Wed, 1 Dec 2021 09:59:03 -0800 Subject: [PATCH] UX: only apply link formats on paste to selections that do not contain links --- .../app/mixins/textarea-text-manipulation.js | 3 ++- .../tests/integration/components/d-editor-test.js | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/app/mixins/textarea-text-manipulation.js b/app/assets/javascripts/discourse/app/mixins/textarea-text-manipulation.js index 6dd67f74ad9..f8ec19f1ff1 100644 --- a/app/assets/javascripts/discourse/app/mixins/textarea-text-manipulation.js +++ b/app/assets/javascripts/discourse/app/mixins/textarea-text-manipulation.js @@ -285,7 +285,8 @@ export default Mixin.create({ this._cachedLinkify && plainText && !handled && - selected.end > selected.start + selected.end > selected.start && + !this._cachedLinkify.test(selectedValue) ) { if (this._cachedLinkify.test(plainText)) { const match = this._cachedLinkify.match(plainText)[0]; diff --git a/app/assets/javascripts/discourse/tests/integration/components/d-editor-test.js b/app/assets/javascripts/discourse/tests/integration/components/d-editor-test.js index aa0808ed860..623739695d6 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/d-editor-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/d-editor-test.js @@ -833,6 +833,19 @@ third line` } ); + testCase( + `pasting a url onto a selection that contains urls and other content will use default paste behavior`, + async function (assert, textarea) { + this.set("value", "Try https://www.discourse.org"); + setTextareaSelection(textarea, 0, 29); + const element = query(".d-editor"); + const event = await paste(element, "https://www.discourse.com/"); + // Synthetic paste events do not manipulate document content. + assert.strictEqual(this.value, "Try https://www.discourse.org"); + assert.strictEqual(event.defaultPrevented, false); + } + ); + (() => { // Tests to check cursor/selection after replace-text event. const BEFORE = "red green blue";