ice icon indicating copy to clipboard operation
ice copied to clipboard

avoid insert inside insert

Open johanneswilm opened this issue 12 years ago • 1 comments

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.

johanneswilm avatar Feb 10 '13 23:02 johanneswilm

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.

delambo avatar Feb 11 '13 17:02 delambo