I poked and read that there is no way to find the current line in div contenteditable, so I'm trying to write a script to best evaluate the current line.
var curLine = 1;
var curColumn = 1;
$(".editable").onkeydown = function(e) {
var keyCode = e.keyCode || e.which;
switch( keyCode ) {
case 13:
console.log("Enter; on line: " + curLine);
curLine++;
break;
case 8:
if( ) {
console.log("Previous line prepended; previous enter reversed; on line: " + curLine);
do {
curLine--;
} while( curLine > 0 );
}
break;
}
};
So, as you can see, I have a few questions. This bit: if( /* current line has a text length of 0 */ )I can’t target the current line and see if the length of the line is 0. In addition, my statement do...whiledoesn’t work, as if I press backspace on the first line on top and again, it goes into negative numbers (when it should just stay at level 1 [ > 0]). Any help would be greatly appreciated.
source
share