diff --git a/public/res/editor.js b/public/res/editor.js index 5b54e28e..b6c4c5c0 100644 --- a/public/res/editor.js +++ b/public/res/editor.js @@ -252,14 +252,20 @@ define([ var selectionRange = selection.getRangeAt(0); var node = selectionRange.startContainer; if((contentElt.compareDocumentPosition(node) & Node.DOCUMENT_POSITION_CONTAINED_BY) || contentElt === node) { - var range = self.createRange({ - container: contentElt, - offsetInContainer: 0 - }, { - container: node, - offsetInContainer: selectionRange.startOffset - }); - var offset = range.toString().length; + var offset = selectionRange.startOffset; + if(node.hasChildNodes() && offset > 0) { + node = node.childNodes[offset - 1]; + offset = node.textContent.length; + } + var container = node; + while(node != contentElt) { + while(node = node.previousSibling) { + if(node.textContent) { + offset += node.textContent.length; + } + } + node = container = container.parentNode; + } if(selection.isBackwards()) { selectionStart = offset + selectionRange.toString().length;