Skip to content

Commit

Permalink
fix(taSelection): Fix selecting end of element being after trailing <br>
Browse files Browse the repository at this point in the history
  • Loading branch information
SimeonC authored and SimeonC committed Feb 5, 2015
1 parent d68c466 commit e1008df
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/DOM.js
Expand Up @@ -315,7 +315,9 @@ function($window, $document, taDOM){

range.selectNodeContents(el);
range.collapse(false);

if(el.childNodes && el.childNodes[el.childNodes.length - 1] && el.childNodes[el.childNodes.length - 1].nodeName === 'br'){
range.startOffset = range.endOffset = range.startOffset - 1;
}
rangy.getSelection().setSingleRange(range);
},
// from http://stackoverflow.com/questions/6690752/insert-html-at-caret-in-a-contenteditable-div
Expand Down Expand Up @@ -420,6 +422,7 @@ function($window, $document, taDOM){
range.deleteContents();
}
}

range.insertNode(frag);
if(lastNode){
api.setSelectionToElementEnd(lastNode);
Expand Down

0 comments on commit e1008df

Please sign in to comment.