0

The following code can make RichTextArea auto-grow-or-shrink vertically based on KeyUp event,and question is how to do same thing when user paste or cut content in or out(Google plus has implemented this).MouseUp and CONTEXTMENU events have been tried,got no luck.Can anybody give a solution?Thanks.

public AutoResizeTextArea()
{
    new Timer()
    {
        @Override
        public void run()
        {
            (doc = ((FrameElement) getElement().cast()).getContentDocument()).getBody()
                    .setAttribute("style", "word-wrap:break-word;overflow:hidden;");
        }
    }.schedule(100);
}


@Override
public void onBrowserEvent(Event event)
{
    switch (DOM.eventGetType(event))
    {
        case Event.ONKEYUP:
            adjustHeight();
            break;
    }
}

private void adjustHeight()
{
    if (doc.getDocumentElement()
            .getOffsetHeight() != doc.getClientHeight())
    {
        setHeight((doc.getDocumentElement()
                .getOffsetHeight() + 19) + "px");
    }
}
Jeromy French
  • 11,812
  • 19
  • 76
  • 129
Alex Luya
  • 9,412
  • 15
  • 59
  • 91

1 Answers1

0

This works for me. I am assuming that your RichTextArea widget = richTextArea variable.

IFrameElement iFrame = IFrameElement.as(richTextArea.getElement());

//listen for paste event
addTextPasteHandler(iFrame);

/**
 * Add a listener for the paste event
 * @param iframe
 */
private native void addTextPasteHandler(IFrameElement iframe)
/*-{
    if(iframe == null)
        return;

    var _this = this;

    var pasteFunction = function(e)
    {
        _this.@com.yourpackagepath.YourClass::handlePaste()();
    }

    iframe.contentWindow.addEventListener('paste', pasteFunction, true);

}-*/;

public void handlePaste() {
    Window.alert("Paste!");
}
YoungDinosaur
  • 1,550
  • 17
  • 22