- var spoint = document.createRange();
- var epoint = document.createRange();
-
- spoint.setStart(range.startContainer, range.startOffset);
- epoint.setStart(range.endContainer, range.endOffset);
-
+ var createPoint = function(container, offset) {
+ var offsetBetweenCommas = function(text, offset) {
+ if(text.length < 2 || offset < 1 || offset > text.length)
+ return false;
+ return text[offset-1] === ',' && text[offset] === ',';
+ }
+ var point = document.createRange();
+ offset = offsetBetweenCommas(container.textContent, offset) ? offset - 1 : offset;
+ point.setStart(container, offset);
+ return point;
+ }
+
+ var spoint = createPoint(range.startContainer, range.startOffset);
+ var epoint = createPoint(range.endContainer, range.endOffset);
+