Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tiny MCE: How to allow people to indent

Tags:

tinymce

I'm trying to find out how to allow people to indent in Tiny MCE editor. Right now, whenever someone presses tab they just move into the next field. Is there any piece of code that will allow them to actually hit tab and have it create a tab for a new paragraph.

like image 566
sinθ Avatar asked Nov 24 '12 16:11

sinθ


People also ask

How do you add an anchor tag in TinyMCE?

Insert anchors (sometimes referred to as a bookmarks).When a user clicks on the anchor button or menu item they will be prompted via a dialog box to enter a string. The string will be inserted into the HTML as an anchor id at the location of the cursor.

How do I disable TinyMCE editor toolbar?

To disable the toolbar, the toolbar option should be provided a boolean value of false .

Does TinyMCE support markdown?

By default, it has basic markdown patterns. There are three types of patterns: inline , block , and replacement patterns. Inline patterns have a start and an end text pattern whereas the block and replacement patterns only have a start .


3 Answers

For newer versions of Tiny MCE editor the following solution worked for me:

setup: function(ed) {
    ed.on('keydown', function(event) {
        if (event.keyCode == 9) { // tab pressed
          if (event.shiftKey) {
            ed.execCommand('Outdent');
          }
          else {
            ed.execCommand('Indent');
          }

          event.preventDefault();
          return false;
        }
    });
}
like image 157
croppio.com Avatar answered Sep 28 '22 12:09

croppio.com


It can be done via nonbreaking plugin available in tinymce

tinymce.init({
  selector: "textarea",  // change this value according to your HTML
  plugins: "nonbreaking",
  mewnubar: "insert",
  toolbar: "nonbreaking",
  nonbreaking_force_tab: true
});

details can be found on https://www.tinymce.com/docs/plugins/nonbreaking/

like image 42
zahid9i Avatar answered Sep 28 '22 11:09

zahid9i


Thariama's solution didn't quite work for me. I agree with Jon Hulka's fix. This seems to work fine on Firefox (mac+pc), Chrome (mac+pc) and Internet Exploder. It's not perfect, but I find it very usable and acceptable. Thanks Jon

So, to wrap op Jon's solution:

tinyMCE.init({
   ...
   setup : function(ed) {
      ed.onKeyDown.add(function(ed, evt) {
          if (evt.keyCode == 9){
            ed.execCommand('mceInsertContent', false, '  ');
            evt.preventDefault();
          }
      });
   }
});
like image 25
Mac Avatar answered Sep 28 '22 11:09

Mac