如何让 gwt 的富文本区域检测内容粘贴和剪切事件?



下面的代码可以使RichTextArea根据KeyUp事件垂直自动增长或缩小,问题是当用户粘贴或剪切内容时如何做同样的事情(谷歌加已经实现了这一点)。鼠标向上和上下文菜单事件已经尝试过,没有运气。谁能给出解决方案?谢谢。

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");
    }
}
这对

我有用。我假设您的富文本区域小部件 = 富文本区域变量。

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!");
}

最新更新