Tinymce 新线事件

Tinymce New line event

我正在为 TinyMce 开发一些编辑,每次光标进入空行(新行或旧行)时我都需要触发一个事件。

我唯一能找到的事件是 nodeChange 还有更好的事件吗?

所以它似乎有效:

tinymce.init({
    selector: '#mytextarea',
    setup : function(editor) {
      editor.on('keyup', function(e) {

        var rng = editor.selection.getRng(true);
        var txt = rng.startContainer.textContent;

        if ( (txt.substring(rng.startOffset - 1, rng.startOffset) == '') &&
             (txt.substring(rng.startOffset, rng.startOffset + 1) == '') ) {

          console.log('empty line !');
        }


      });
    }
});

This is the JSFiddle

更新:此更新还识别仅包含图像的行

tinymce.init({
    selector: '#mytextarea',
    setup : function(editor) {
      editor.on('keyup', function(e) {

        var rng = editor.selection.getRng(true);
        var txt = rng.startContainer.textContent;

        if ( (txt.substring(rng.startOffset - 1, rng.startOffset) == '') &&
             (txt.substring(rng.startOffset, rng.startOffset + 1) == '') &&
             (rng.startContainer.outerHTML.indexOf('<img')==-1)) {
          console.log('empty line !');
        }

      });
    }
});

This is the new JSFiddle