{
// save the selection and scroll position for restoration
int scrollPosition = docDisplay_.getScrollTop();
Position start = docDisplay_.getSelectionStart();
Position end = docDisplay_.getSelectionEnd();
AnchoredSelection anchoredSelection =
docDisplay_.createAnchoredSelection(start,end);
// execute the command
command.execute();
// restore the selection and scroll position
anchoredSelection.apply();
docDisplay_.scrollToY(scrollPosition);
}