Rollback selection calculation

This commit is contained in:
benweet 2014-12-15 22:05:26 +00:00
parent edfd8a1603
commit 65d2c6c455

View File

@ -252,14 +252,20 @@ define([
var selectionRange = selection.getRangeAt(0); var selectionRange = selection.getRangeAt(0);
var node = selectionRange.startContainer; var node = selectionRange.startContainer;
if((contentElt.compareDocumentPosition(node) & Node.DOCUMENT_POSITION_CONTAINED_BY) || contentElt === node) { if((contentElt.compareDocumentPosition(node) & Node.DOCUMENT_POSITION_CONTAINED_BY) || contentElt === node) {
var range = self.createRange({ var offset = selectionRange.startOffset;
container: contentElt, if(node.hasChildNodes() && offset > 0) {
offsetInContainer: 0 node = node.childNodes[offset - 1];
}, { offset = node.textContent.length;
container: node, }
offsetInContainer: selectionRange.startOffset var container = node;
}); while(node != contentElt) {
var offset = range.toString().length; while(node = node.previousSibling) {
if(node.textContent) {
offset += node.textContent.length;
}
}
node = container = container.parentNode;
}
if(selection.isBackwards()) { if(selection.isBackwards()) {
selectionStart = offset + selectionRange.toString().length; selectionStart = offset + selectionRange.toString().length;