I use the RSyntaxTextArea component in my project, and it's really helped. But recently I met a little problem when I want to do the undo operation. It will remove the whole content that input. What I want is remove only one letter at a time like Microsoft word program does. I try to read the code, and I found the "" concept which means I can undo one word maybe at a time. I thought this function was controlled by the inProgress boolean flag in CompoundEdit class. So I use the reflect to invoke the end() method in CompoundEdit to set the flag to false when I typed space key. I hope it can happened when I input "ab cd" and typed 'Ctrl + z', the 'cd' will be removed and 'ab' are remained. But it didn't work as I expected. Am I doing something wrong? Code list below.
java code:
textArea.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.VK_SPACE) {
try {
CompoundEdit ce = CompoundEdit.class.newInstance();
System.out.println("Is in progress1? "
+ ce.isInProgress()); // true
mgr.getClass().getDeclaredField("compoundEdit")
.getType().getSuperclass()
.getMethod("end", null).invoke(ce, null);
System.out.println("Is in progress2? "
+ ce.isInProgress());// false
} catch (Exception e) {
// ignore
e.printStackTrace();
}
}
}
...
Waiting for your help. Thanks a lot!
/Vanessa
