Help adding a button to the new composer
-
In the old composer, of nodebb v2, I used this code to add to the composer toolbar a button that wraps the selected text in Backtick (creates
such a thing
) :(async function () { const { require } = app; "use strict"; /* globals require, $ */ const [formatting, controls] = await app.require(['composer/formatting', 'composer/controls']); formatting.addButton( "fa fa-terminal", function (textarea, selectionStart, selectionEnd) { if (selectionStart === selectionEnd) { var block = controls.getBlockData(textarea, "`", selectionStart); if (block.in && block.atEnd) { controls.updateTextareaSelection( textarea, selectionStart + 1, selectionStart + 1 ); } else { controls.insertIntoTextarea(textarea, `\`code\``); controls.updateTextareaSelection( textarea, selectionStart + 1, selectionStart + "code".length + 1 ); } } else { var wrapDelta = controls.wrapSelectionInTextareaWith(textarea, "`"); controls.updateTextareaSelection( textarea, selectionStart + 1 + wrapDelta[0], selectionEnd + 1 - wrapDelta[1] ); } }, "code" ); })();
After the upgrade to v3 the button was added, but does not respond and there is no error.
I checked the matter and I see that while the original buttons are wrapped in:<a href="#" data-format="some"></a>
The button added by calling
formatting.addButton
is not wrapped in this.
I tried to go through the changes at https://github.com/NodeBB/nodebb-plugin-composer-default but I couldn't find where the problem is exactly, I would appreciate it if you could help me!
Thanks -
-
-
@josef thanks for reporting, looks like composer.addComposerButtons function wasn't updated to use the new markup. I've fixed it in https://github.com/NodeBB/nodebb-plugin-composer-default/commit/eb271926b318a1815b7f135e16df78b1709f12ad, [email protected] if you want to get the fix.
-
@baris Thanks, confirming it works in
[email protected]