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 6dd67f74ad..f8ec19f1ff 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 aa0808ed86..623739695d 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";