formattinymcepre

Add the Code Format to its own button in the toolbar


I'm doing my own TinyMCE toolbar and I want to add the exact same functionality as when you choose Format>Code, but as its own button in the toolbar. Is that possible and how should I do that?

Thank you!


Solution

  • I figured it out. You can add your own button and then have it execute a command.

    setup: function(editor) {
        editor.ui.registry.addButton('strikeout', {
          icon: 'sourcecode',
          tooltip: "Format as code",
          onAction: function() {
            editor.execCommand('mceToggleFormat', false, 'code');
          }
        });
    }