RSyntaxTextArea, set initial text

Questions on using RSyntaxTextArea should go here.

Moderator: robert

RSyntaxTextArea, set initial text

Postby bax1989 » Fri Nov 16, 2012 4:54 pm

I create an RSyntaxTextArea and set the text on it.
The problem is that the undo operation removes this initial text. I want the content to be 'undoable' till this initial text.
One logical way to achieve this would be to pass the text to the constructor, but in this case there is an NPE in JTextComponent.setCaretPosition.
Any solution ?
Thanks.
bax1989
 

Re: RSyntaxTextArea, set initial text

Postby robert » Sat Nov 17, 2012 3:46 pm

Simply call textArea.discardAllEdits() after setting the initial text.

If you're implementing a full-blown text editor, that loads files off of a disk, you can also use a TextEditorPane and call load(FileLocation, null), which will handle things like this for you.
User avatar
robert
 
Posts: 796
Joined: Sat May 10, 2008 5:16 pm

Re: RSyntaxTextArea, set initial text

Postby Guest » Mon Nov 19, 2012 1:55 pm

Thank you, switched to TextEditorPane.
Another question : I listen for TextEditorPane.DIRTY_PROPERTY property changes on the editor(for maintaining an asterisk on tab title which indicates that the file is modified), I receive an event when I modify the file, but when a undo all changes I don't receive any event, the dirty status is reset only after save/reload. Is it so by design or there's some fix ?
Guest
 

Re: RSyntaxTextArea, set initial text

Postby robert » Tue Nov 20, 2012 2:58 am

You're right, the dirty flag doesn't clear if you go back to the beginning of the undo stack. This was just a personal preference on my part. I know that most editors these days consider being at the beginning of the undo stack as being "not dirty," since there should be no visible modifications in the editor. I'll make this change in the next release.
User avatar
robert
 
Posts: 796
Joined: Sat May 10, 2008 5:16 pm

Re: RSyntaxTextArea, set initial text

Postby bax » Tue Nov 20, 2012 8:35 am

thank you for prompt answers
bax
 
Posts: 4
Joined: Fri Nov 16, 2012 4:42 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 1 guest