A platform for community discussion. Free, open, simple.
DEV: adds support for replaceText in toolbarEvent (#28512)
Joffrey JAFFEUX2829b670f988
diff --git a/app/assets/javascripts/discourse/app/components/d-editor.js b/app/assets/javascripts/discourse/app/components/d-editor.jsindex c1fc8d1f6f4..7e7eac68917 100644--- a/app/assets/javascripts/discourse/app/components/d-editor.js+++ b/app/assets/javascripts/discourse/app/components/d-editor.js@@ -812,6 +812,8 @@ export default Component.extend(TextareaTextManipulation, {addText: (text) => this.addText(selected, text),getText: () => this.value,toggleDirection: () => this._toggleDirection(),+ replaceText: (oldVal, newVal, opts) =>+ this.replaceText(oldVal, newVal, opts),};},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.jsindex 7cb36b83451..418571ba9d4 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@@ -646,6 +646,29 @@ third line`assert.strictEqual(textarea.getAttribute("dir"), "rtl");});+ test("toolbar event supports replaceText", async function (assert) {+ withPluginApi("0.1", (api) => {+ api.onToolbarCreate((toolbar) => {+ toolbar.addButton({+ id: "replace-text",+ icon: "times",+ group: "extras",+ action: () => {+ toolbar.context.newToolbarEvent().replaceText("hello", "goodbye");+ },+ condition: () => true,+ });+ });+ });++ this.value = "hello";++ await render(hbs`<DEditor @value={{this.value}} />`);+ await click("button.replace-text");++ assert.strictEqual(this.value, "goodbye");+ });+testCase(`doesn't jump to bottom with long text`,async function (assert, textarea) {