public String replaceSelection(String value, boolean collapseSelection) { Selection selection = getSession().getSelection(); String oldValue = getSession().getTextRange(selection.getRange()); replaceSelection(value); if (collapseSelection) { collapseSelection(false); } return oldValue; }
public void collapseSelection(boolean collapseToStart) { Selection selection = getSession().getSelection(); Range rng = selection.getRange(); Position pos = collapseToStart ? rng.getStart() : rng.getEnd(); selection.setSelectionRange(Range.fromPoints(pos, pos)); }