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:
Joffrey JAFFEUX 2024-08-23 11:44:27 +02:00 committed by GitHub
parent 17db30ab7e
commit 2829b670f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 0 deletions

View File

@ -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),
};
},

View File

@ -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) {