I couldnt help myself and looked down the rabit hole a bit. haha and now are 2 hours gone already.
you need to add the handlebars file like this to display the button
and then you need some action similar to the one in the poll plugin:
pollEnabled &&
(pmWithNonHumanUser ||
(this.currentUser &&
(this.currentUser.staff ||
this.currentUser.trust_level >= minimumTrustLevel)))
);
},
actions: {
showPollBuilder() {
showModal("poll-ui-builder").set("toolbarEvent", this.toolbarEvent);
}
}
});
api.addToolbarPopupMenuOptionsCallback(() => {
return {
action: "showPollBuilder",
icon: "chart-bar",
label: "poll.ui_builder.title",
condition: "canBuildPoll"
we can feed the poll builder modal a “fake” toolbar event, but the issue is that you also need to replicate the logic in the editor component
}
const selected = this._getSelected(button.trimLeading);
const toolbarEvent = {
selected,
selectText: (from, length) => this._selectText(from, length),
applySurround: (head, tail, exampleKey, opts) =>
this._applySurround(selected, head, tail, exampleKey, opts),
applyList: (head, exampleKey, opts) =>
this._applyList(selected, head, exampleKey, opts),
addText: text => this._addText(selected, text),
replaceText: text => this._addText({ pre: "", post: "" }, text),
getText: () => this.value,
toggleDirection: () => this._toggleDirection()
};
if (button.sendAction) {
return button.sendAction(toolbarEvent);
} else {
button.perform(toolbarEvent);
}
the part with _getSelected and _addText. I would be very interested to know if there is some api to add text programmatically to the editor textarea from “the outside”.