A platform for community discussion. Free, open, simple.
FIX: `applySurround` should detect both sides when deleting surrounde… (#34243)
Lincab38084846220
diff --git a/app/assets/javascripts/discourse/app/lib/textarea-text-manipulation.js b/app/assets/javascripts/discourse/app/lib/textarea-text-manipulation.jsindex 9a1cf66171a..6833e00d091 100644--- a/app/assets/javascripts/discourse/app/lib/textarea-text-manipulation.js+++ b/app/assets/javascripts/discourse/app/lib/textarea-text-manipulation.js@@ -289,8 +289,8 @@ export default class TextareaTextManipulation {if (operation !== OP.ADDED &&- ((l.slice(0, hlen) === hval && tlen === 0) ||- (tail.length && l.slice(-tlen) === tail))+ l.slice(0, hlen) === hval &&+ (tlen === 0 || l.slice(-tlen) === tail)) {operation = OP.REMOVED;if (tlen === 0) {diff --git a/app/assets/javascripts/discourse/tests/unit/lib/text-area-manipulaton-test.js b/app/assets/javascripts/discourse/tests/unit/lib/text-area-manipulaton-test.jsnew file mode 100644index 00000000000..af1b380127c--- /dev/null+++ b/app/assets/javascripts/discourse/tests/unit/lib/text-area-manipulaton-test.js@@ -0,0 +1,54 @@+import { getOwner } from "@ember/owner";+import { setupTest } from "ember-qunit";+import { module, test } from "qunit";+import TextareaTextManipulation from "discourse/lib/textarea-text-manipulation";++module("Unit | Utility | text-area-manipulation", function (hooks) {+ setupTest(hooks);++ test("applySurround - add", async function (assert) {+ const textarea = document.createElement("textarea");+ document.body.appendChild(textarea);+ const manipulation = new TextareaTextManipulation(getOwner(this), {+ textarea,+ });++ textarea.value = "Hello World";+ textarea.select();+ manipulation.applySurroundSelection("**", "**", "example");++ assert.strictEqual(textarea.value, "**Hello World**");+ });++ test("applySurround - remove", async function (assert) {+ const textarea = document.createElement("textarea");+ document.body.appendChild(textarea);+ const manipulation = new TextareaTextManipulation(getOwner(this), {+ textarea,+ });++ textarea.value = "**Hello World**";+ textarea.select();+ manipulation.applySurroundSelection("**", "**", "example");++ assert.strictEqual(textarea.value, "Hello World");+ });++ test("applySurround - one side", async function (assert) {+ const textarea = document.createElement("textarea");+ document.body.appendChild(textarea);+ const manipulation = new TextareaTextManipulation(getOwner(this), {+ textarea,+ });++ textarea.value = "Hello World**";+ textarea.select();+ manipulation.applySurroundSelection("**", "**", "example");+ assert.strictEqual(textarea.value, "**Hello World****");++ textarea.value = "**Hello World";+ textarea.select();+ manipulation.applySurroundSelection("**", "**", "example");+ assert.strictEqual(textarea.value, "****Hello World**");+ });+});