How to strip formating on paste? (rich text box)

123 views
Skip to first unread message

darkflame

unread,
Sep 4, 2009, 5:59:42 PM9/4/09
to Google Web Toolkit
I'm using a rich text area, and Ive run into the problem that when
users cut and paste from some applications, a lot of junk formating is
pasted as well.

Is there any method to catch the paste, and strip this data out?
So, while users can use it for rich text editing, they can only paste
data in as plane text.

Dalla

unread,
Sep 5, 2009, 5:16:17 AM9/5/09
to Google Web Toolkit
RichTextArea extends FocusWidget, which has a number of handlers for
keyboard events.
This snippet will let you catch a paste, assuming that the users paste
using CTRL+V

RichTextArea area = new RichTextArea();
area.addKeyDownHandler(new KeyDownHandler() {
@Override
public void onKeyDown(KeyDownEvent event) {
if (event.isControlKeyDown() && event.getNativeKeyCode() == 86) {
System.out.println("Paste");
}
}
});

Not sure how you would catch the paste event if it came from a right-
click context menu
or the browser menu though...

ThomasWrobel

unread,
Sep 5, 2009, 1:53:34 PM9/5/09
to Google Web Toolkit
Thanks, thats 1/3rd of the problem solved then ;)
Guess I'll need to write a routine that strips all formating except
for bold,italic,underline, links etc.
Probably need to use a regex. grr. I always get muddled with them.
Reply all
Reply to author
Forward
0 new messages