如果插入符位于tinyMCE 段落开头,则防止退格

cyr*_*rat 4 tinymce

如果我的光标位置位于第一段的开头,我需要防止退格。整件事是我想防止删除编辑器中的第一段。

Tha*_*ama 5

你可以做(​​使用Tinymce3)类似的事情

tinyMCE.init({
    mode : "textareas",
    ...
    setup : function(ed) {

        ed.onKeyDown.add(function(ed, event) {

            var range = ed.selection.getRng();

            // case: first editor node is the node with the caret in it
            if (range.startOffset == 0 && ed.getBody().getNode() == ed.getBody().firstChild)
            {
               event.preventDefault;
               return false;

            }
        });
    }
});
Run Code Online (Sandbox Code Playgroud)

由于 TinyMCE 4x keydown、keypress 和 keyup 都成为 editor.on 的事件,因此可以通过执行以下操作获得相同的结果:

ed.on('keydown', function( args ) {

  var range = ed.selection.getRng();

     // First editor node is the node with the caret in it
     if ( range.startOffset === 0 ) {
       event.preventDefault();
       return false;
     }

 }); 
Run Code Online (Sandbox Code Playgroud)