As for the blocking elements in the contenteditable div; I use spaces that need to be locked and they do not fire keydown events, so set the event to a div and check the range if it is a locked element.
I use google closure library to get range:
goog.events.listen(document.getElementById("userInput"),//userInput= contenteditable div [goog.events.EventType.KEYDOWN, goog.events.EventType.PASTE], function(e){ if(32<e.keyCode&&e.keyCode<41){//page up,down,home,end and arrow return; } var el=goog.dom.Range.createFromWindow() .getContainerElement(); if(el.className.indexOf("locked")!==-1){ e.preventDefault(); } });
I will consider filling a locked range with & nbsp; if spaces did not exist before or after the element and did not place it here after receiving the decision.
Filling in the blanks without checking is completed, as extra spaces will be deleted later. It looks funny, but it's better not to add text.
source share