nytimes / ice

track changes with javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IE 9: First letter on a new line is outside of <insert> tag.

jnssn opened this issue · comments

The first letter typed in a new line is excluded from the tracked changes because it's outside the <insert> tag. Using the tinymce plugin demo (http://nytimes.github.io/ice/demo), starting a new line after the first paragraph, I type:

This is a test

Viewing the HTML shows this:
<p><span style="background-color: #e5ffcd;">T<insert class="ins cts-3" title="Inserted by Geoffrey Jellineck - 12/17/2013 5:25pm" data-cid="9" data-userid="11" data-username="Geoffrey Jellineck" data-time="1387329905681">his is a test</insert></span></p>

Deleting that line leaves you with a single redacted "T", while clicking Accept Changes removes the <insert> tag, but it doesn't appear to accept them because the editor leaves the green span intact.

this isn't just IE9. maybe not this specific issue, but there is an issue with chrome even where the first word of a new line is outside of the insert tag. Though it could be an issue with some compatibility thing with TinyMCE 4.x.x (see: #105)

Is there a solution for this issue?

I am seeing this issue in IE11.

For what it is worth, I was able to fix this issue by changing the following code in ice.js in the function _insertNode.

Change:

if (insertingDummy) {
// Create a selection of the dummy character we inserted
// which will be removed after it bubbles up to the final handler.
range.setStart(node, 0);
} else {
range.collapse();
}

to
if (insertingDummy) {
// Create a selection of the dummy character we inserted
// which will be removed after it bubbles up to the final handler.
//range.setStart(node, 0);
// FIX FOR IE
range.collapse();
} else {
range.collapse();
}

I have a vague idea of why it works, but really need to study the code a bit more.
I fixed it mostly though trial and error.