Rich text editor and popup

67 views
Skip to first unread message

rabi...@qis.co.in

unread,
Nov 23, 2007, 6:36:37 AM11/23/07
to GWT Rich-Text Editor
I have a parent window and a child window(popup).
In parent window, there is a dropdown list.When i selecting one value
from this dropdown, the child window is displayed.After adding
contents to textarea of this child window, i need to copy the contents
to rich text editor of parent window.My problem is that the content is
not copied to rich text editor.Can anyone help me?
Thanks.

Yegor

unread,
Nov 27, 2007, 4:53:43 PM11/27/07
to GWT Rich-Text Editor
The closest method to achieve this is probably to use the getHTML()
and setHTML(String) methods to copy the contents. Unfortunately there
is no way that I know of to get the keyboard cursor position in the
Editor, so you can only append, prepend or add the text at a
predefined place.

Yegor

Skipper Dave

unread,
Jan 13, 2008, 11:35:19 AM1/13/08
to GWT Rich-Text Editor
I too was frustrated by the fact that I could not get access to the
cursor position as I wanted to insert something at the current cursor
position.. So I thought.. I have getHTML() and setHTML().. and I have
the ability to set images at the current cursor position

Here is some code that I came up with yesterday.. It truly is a hack
(in my mind) but I was desparate for some kind of solution even if was
half baked..

--------------------------

package dtb.gwt.common.client.ui.util.richtextarea;

import com.google.gwt.user.client.ui.RichTextArea;

/**
* Inserts text at the current cursor position within a RichTextArea.
*
* @author David Balme
*
*/
public class StringInserter {

private int dummyMarkerCounter=0;

public void insertStringAtCurrentPosition(RichTextArea richTextArea,
String stringToAdd) {

dummyMarkerCounter++; // I have this counter to create a unique
marker every time that this method is called.
String dummyURL = "http://wwwdummycom/MARKER_"+dummyMarkerCounter;
String imgPatternMatch = "<[Ii][Mm][Gg]\\s*.*[sS][Rr][Cc]\\s*=\\s*.*\
\x22http://wwwdummycom/MARKER_"+dummyMarkerCounter+"\\x22>";

// Insert dummy image at current cursor position
richTextArea.getExtendedFormatter().insertImage(dummyURL);
String sHTML = richTextArea.getHTML();

// replace dummy image with the text we want, use regexp to find img
just inserted
sHTML = sHTML.replaceAll(imgPatternMatch, stringToAdd);

// Set the new text.. problem with this is that after the setHTML()
call,
// we lose the current cursor position (at least in
IE7).. <sigh>

richTextArea.setHTML(sHTML);

}
}
--------------------------

Example call within in a form that contains a RichTextArea


private StringInserter stringInserter = new StringInserter();

private void addTokenToRichTextArea(String sToken) {
stringInserter.insertStringAtCurrentPosition(richTextArea, "["+sToken
+"]");
> > Thanks.- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages