如何制作gwt';s RichTextArea是否检测内容粘贴和剪切事件?
下面的代码可以使RichTextArea根据KeyUp事件自动垂直增长或收缩,问题是当用户粘贴或剪切内容时如何做同样的事情(Google plus已经实现了这一点)。MouseUp和CONTEXTMENU事件已经尝试过,但没有成功。有人能给出解决方案吗?谢谢如何制作gwt';s RichTextArea是否检测内容粘贴和剪切事件?,gwt,copy-paste,cut,rich-text-editor,autogrow,Gwt,Copy Paste,Cut,Rich Text Editor,Autogrow,下面的代码可以使RichTextArea根据KeyUp事件自动垂直增长或收缩,问题是当用户粘贴或剪切内容时如何做同样的事情(Google plus已经实现了这一点)。MouseUp和CONTEXTMENU事件已经尝试过,但没有成功。有人能给出解决方案吗?谢谢 public AutoResizeTextArea() { new Timer() { @Override public void run() { (d
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");
}
}
这对我有用。我假设您的RichTextArea widget=RichTextArea变量
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!");
}