Expand to word boundary.
Shows an extremely naive way to expand selection to word boundaries.
by lddubeau
HTML
<script src="http://rangy.googlecode.com/svn/trunk/dev/uncompressed/rangy-core.js"></script>
<div tabindex="-1">
<p id="q" contenteditable="true" tabindex="-1">Example text.</p>
</div>
<button id="set">Set selection.</button>
JavaScript
var $q = $("#q");
var $expand = $("#set");
$expand.click(function () {
var text = $q[0].childNodes[0];
var r = rangy.createRange();
r.setStart(text, 2);
r.setEnd(text, 4);
rangy.getSelection().setSingleRange(r);
});