As I googled to here several times when I developing IntelliJ plugin emacsIDEAs, I will leave my solution here for someone who need it.
usually change to document need be done in runWriteAction,
and for undo changes to document need called in CommandProcessor.getInstance().executeCommand
so the solution is: call executeCommand in runWriteAction, then the changes will be undoable.
protected Runnable getRunnableWrapper(final Runnable runnable) {
return new Runnable() {
@Override
public void run() {
CommandProcessor.getInstance().executeCommand(_editor.getProject(), runnable, "cut", ActionGroup.EMPTY_GROUP);
}
};
}
final Runnable runnable = new Runnable() {
@Override
public void run() {
selectJumpArea(jumpTargetOffset);
_editor.getSelectionModel().copySelectionToClipboard();
EditorModificationUtil.deleteSelectedText(_editor);
_editor.getSelectionModel().removeSelection();
}
};
ApplicationManager.getApplication().runWriteAction(getRunnableWrapper(runnable));
code repo: https://github.com/whunmr/emacsIDEAs