ice
ice copied to clipboard
avoid insert inside insert
hey, while working on another project, I came across a discovery that works for Webkit:
in handleEnter, inside a Mongolian vowel space character (can be anything, but this one doesn't take any space:
emptySpaceNode = document.createTextNode('\u180e');
Put it outside the insert, where you want the caret to be when the new paragraph is created.
range.selectNodeContents(emptySpaceNode);
range.collapse();
selection = rangy.getSelection();
selection.removeAllRanges();
selection.addRange(range);
Now you can remove it again, but do it with a timer, so that the Enter is being executed first:
function removeEmptySpace() {
jQuery(emptySpaceNode).remove();
}
setTimeout(removeEmptySpace, 1);
I haven'ttried this in Firefox yet.
Interesting - I was trying something similar in Webkit and it didn't work. I'll try it out again when I get back to handleEnter. At the moment, I'm very close to merging your branch into master.