- var textNodeIdx = parent.contents().index($(selection.anchorNode));\r
- if(selection.anchorNode != selection.focusNode) {\r
- textNodeIdx = [textNodeIdx, parent.contents().index($(selection.focusNode))];\r
+ if(selection.anchorNode === selection.focusNode) {\r
+ if(offsetStart > offsetEnd) {\r
+ var tmp = offsetStart;\r
+ offsetStart = offsetEnd;\r
+ offsetEnd = tmp;\r
+ }\r
+ textNodeIdx = parentContents.index($anchorNode);\r
+ } else {\r
+ if(parentContents.index($anchorNode) > parentContents.index($focusNode)) {\r
+ offsetStart = selection.focusOffset;\r
+ offsetEnd = selection.anchorOffset;\r
+ }\r
+ textNodeIdx = [parentContents.index($anchorNode), parentContents.index($focusNode)];\r