final StringBuilder modifiedText = new StringBuilder(text);
modifiedText.replace(begin, end, modifiedPortion.toString());
// replace the text with the modified idented text
textEditor.disableUndo();
XJUndo undo = textEditor.getTextPaneUndo();
undo.addEditEvent(new UndoableRefactoringEdit(text, modifiedText.toString()));
setText(modifiedText.toString());
textEditor.enableUndo();
// adjust the selection
getCaret().setDot(selectionStart);