mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: adds support for replaceText in toolbarEvent (#28512)
This function was available in textarea manipulation mixin, but not exposed as other functions like addText, applySurround, ...
This commit is contained in:
@@ -812,6 +812,8 @@ export default Component.extend(TextareaTextManipulation, {
|
|||||||
addText: (text) => this.addText(selected, text),
|
addText: (text) => this.addText(selected, text),
|
||||||
getText: () => this.value,
|
getText: () => this.value,
|
||||||
toggleDirection: () => this._toggleDirection(),
|
toggleDirection: () => this._toggleDirection(),
|
||||||
|
replaceText: (oldVal, newVal, opts) =>
|
||||||
|
this.replaceText(oldVal, newVal, opts),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -646,6 +646,29 @@ third line`
|
|||||||
assert.strictEqual(textarea.getAttribute("dir"), "rtl");
|
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(
|
testCase(
|
||||||
`doesn't jump to bottom with long text`,
|
`doesn't jump to bottom with long text`,
|
||||||
async function (assert, textarea) {
|
async function (assert, textarea) {
|
||||||
|
|||||||
Reference in New Issue
Block a user