guardian / scribe

DEPRECATED: A rich text editor framework for the web platform
http://guardian.github.io/scribe/
Apache License 2.0
3.51k stars 245 forks source link

Selection range incorrect when inside a list #430

Closed ghost closed 8 years ago

ghost commented 9 years ago

I have a plugin and inside my execute method I am doing the following:

var selection = new scribe.api.Selection();
var range = selection.range;
var newLine = document.createElement('p');

// Insert the new P node after the OL
range.startContainer.parentNode.parentNode.parentNode.insertBefore(newLine, range.startContainer.parentNode.parentNode.nextSibling);

// Select the new P node. I am assuming that this should set the startContaine, endContainer and all other properties of range.
range.selectNode(newLine);

selection.selection.removeAllRanges();
selection.selection.addRange(range);

I have the following list already inside the target div:

<ol><li>some content</li><li>some more content</li></ol>

I place the cursor at the end of the second LI and then call execute. I would expect the selection range start container to be the new P element I created and called selectNode on. This is not the case, instead the div element is selected.

Am I misunderstanding something or does the selection process have an issue with lists?

I would also like to mention if that if I do this without a list and just insert the new P tag in the target div, everything works as expected. The range points to the new P tag.

rrees commented 8 years ago

I'm afraid this is beyond my knowledge, maybe someone else can jump in and help.