Joan
Joan

Reputation: 729

Add space before characters while typing in TinyMCE

I'm trying to achieve a MS-Word-like management for non-breaking spaces before some characters:

While typing, automatically add non-breaking space before ?, !, : etc. (or replace normal space with non-breaking), or add space after «, etc. (which are rules in French, for e.g.).

I was doing this in PHP before displaying the content, but it should be much better to have it directly in the Wysiwyg.

Cannot find any plugin / ways to achieve that. Suggestions?

Thanks!

Upvotes: 1

Views: 548

Answers (1)

Thariama
Thariama

Reputation: 50832

You can add a tinymce event on keydown (just add setup to your tinymce config parameters):

....
plugins : 'popup1, popup2,...',
setup : function(ed) {
    //register event handler
    ed.onKeyDown.add(function onkeydown(ed, e)
    {
        // example for '!'
        if(e.charCode == 49 && evt.shiftKey)
        {
            ed.execCommand('insertHTML', false, ' ');
        }
    });
}

Upvotes: 1

Related Questions