UX: only apply link formats on paste to selections that do not contain bbcode-like tags (#15204)

This commit is contained in:
Kerry Liu 2021-12-09 08:41:44 -08:00 committed by GitHub
parent e0ea16f05d
commit c8af3e7bc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -286,7 +286,10 @@ export default Mixin.create({
plainText &&
!handled &&
selected.end > selected.start &&
!this._cachedLinkify.test(selectedValue)
// text selection does not contain url
!this._cachedLinkify.test(selectedValue) &&
// text selection does not contain a bbcode-like tag
!selectedValue.match(/\[\/?[a-z =]+?\]/g)
) {
if (this._cachedLinkify.test(plainText)) {
const match = this._cachedLinkify.match(plainText)[0];

View File

@ -846,6 +846,19 @@ third line`
}
);
testCase(
`pasting a url onto a selection that contains bbcode-like tags will use default paste behavior`,
async function (assert, textarea) {
this.set("value", "hello [url=foobar]foobar[/url]");
setTextareaSelection(textarea, 0, 30);
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, "hello [url=foobar]foobar[/url]");
assert.strictEqual(event.defaultPrevented, false);
}
);
(() => {
// Tests to check cursor/selection after replace-text event.
const BEFORE = "red green blue";