Skip to content

Commit

Permalink
Rollback selection calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
benweet committed Dec 15, 2014
1 parent edfd8a1 commit 65d2c6c
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions public/res/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 65d2c6c

Please sign in to comment.