dist/angular-onselect.js
function snapToWord() {
        if (isHighlighted()) {
          throw new Error("Can't modify range after highlighting");
        }

        var start = selection.range.startOffset;
        var startNode = selection.range.startContainer;

        while (startNode.textContent.charAt(start) != ' ' && start > 0) {
          start--;
        }
        if (start != 0 && start != selection.range.startOffset) {
          start++;
        }

        var end = selection.range.endOffset;
        var endNode = selection.range.endContainer;
        while (endNode.textContent.charAt(end) != ' ' && end < endNode.length) {
          end++;
        }

        selection.range.setStart(startNode, start);
        selection.range.setEnd(endNode, end);

        selection.text = selection.range.toString();
      }
function snapToWord() {
        if (isHighlighted()) {
          throw new Error("Can't modify range after highlighting");
        }

        var start = selection.range.startOffset;
        var startNode = selection.range.startContainer;

        while (startNode.textContent.charAt(start) != ' ' && start > 0) {
          start--;
        }
        if (start != 0 && start != selection.range.startOffset) {
          start++;
        }

        var end = selection.range.endOffset;
        var endNode = selection.range.endContainer;
        while (endNode.textContent.charAt(end) != ' ' && end < endNode.length) {
          end++;
        }

        selection.range.setStart(startNode, start);
        selection.range.setEnd(endNode, end);

        selection.text = selection.range.toString();
      }
function snapToWord ( ) { if ( isHighlighted ( ) ) { throw new Error ( "Can't modify range after highlighting" ) ; } var start = selection . range . startOffset ; var startNode = selection . range . startContainer ; while ( startNode . textContent . charAt ( start ) != ' ' && start > 0 ) { start -- ; } if ( start != 0 && start != selection . range . startOffset ) { start ++ ; } var end = selection . range . endOffset ; var endNode = selection . range . endContainer ; while ( endNode . textContent . charAt ( end ) != ' ' && end < endNode . length ) { end ++ ; } selection . range . setStart ( startNode , start ) ; selection . range . setEnd ( endNode , end ) ; selection . text = selection . range . toString ( ) ; }
Expand the current range so that both the beginning and end end at word boundaries.

@memeberOf onselect.Selection
@name snapToWord
Expand the current range so that both the beginning and end end at word boundaries .