I am using contenteditable
where I because of some business scenarios, I need to track the new line breaks <br>
. To handle that, I did below steps:
keydown
event, I stopped "enter" key event (keyCode = 13)keyup
event of "Enter", I fire execCommand
as $window.document.execCommand('insertHTML',true,'<br class="new">');
It works like a charm unless I am at the line end.
<br class="new">
but line change of cursor do not happen although the html
is inserted.innerHTML
is inserted.Here is the plunkr. Please check console to see the html
It works perfect if there is any character before cursor
I hope I have explained my problem clearly. Any suggestions please
Although it seems like a workaround, but you can use
$window.document.execCommand('insertHTML',true,'<br class="new"> ');
It'll serve your purpose with a whitespace , which I think can be ignored.