I need to prevent backspace if my cursor position is in the beginning of the first paragraph. The whole thing is that I want to prevent the deletion of my first paragraph in the editor.
You can do (using Tinymce3) something like
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;
}
});
}
});
Since TinyMCE 4x keydown, keypress and keyup all became events of editor.on, the same result can be achieved doing the following:
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;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With