wasabeef / richeditor-android

RichEditor for Android is a beautiful Rich Text WYSIWYG Editor for Android.
Apache License 2.0
6.26k stars 1.2k forks source link

Clipboard cannot set or getData #25

Open liuchonghui opened 9 years ago

liuchonghui commented 9 years ago

RE.editor.addEventListener("paste", function(evt) { evt.preventDefault(); var pasteData = evt.clipboardData; // pasteData getData.length = 0 } How to fix it..I want to remove css style from pasted contents.

liuchonghui commented 9 years ago

Fixed.I tried this way: js add: RE.editor.addEventListener("paste", function(evt) { evt.preventDefault(); var plain = ClipboardReader.getClipboardDataAsText(); RE.insertHTML(plain);
}); RichEditor.java add: private class ClipboardReader { public String getClipboardDataAsText() { String plainText = ""; ClipboardManager cm = (ClipboardManager) getContext() .getSystemService(Context.CLIPBOARD_SERVICE); ClipData cd = cm.getPrimaryClip(); if (cd != null && cd.getItemAt(0) != null) { Item item = cd.getItemAt(0); plainText = item.getText().toString(); } return plainText; } } and regist "ClipboardReader": addJavascriptInterface(new ClipboardReader(), "ClipboardReader");