How can I undo one letter at one time?

Questions on using RSyntaxTextArea should go here.

Moderator: robert

How can I undo one letter at one time?

Postby vanessa » Wed Aug 08, 2012 1:52 am

Hi Robert,

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
vanessa
 
Posts: 2
Joined: Mon Aug 06, 2012 8:18 am

Re: How can I undo one letter at one time?

Postby robert » Fri Aug 10, 2012 12:46 pm

If I'm not mistaken, Microsoft Word does the same thing RSTA does - an undo removes all contiguously-typed letters in a single undo (unless there's a very long pause - maybe 10 seconds - between typing those contiguous letters).

I'm not sure of an easy way to accomplish what you want. Do you want each word to be considered an undoable edit, or each letter?
User avatar
robert
 
Posts: 788
Joined: Sat May 10, 2008 5:16 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 1 guest

cron