Skip to content

Commit

Permalink
Insert clipboard text on paste event
Browse files Browse the repository at this point in the history
  • Loading branch information
wisnup committed Sep 24, 2020
1 parent a62dde3 commit 74bce0d
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.android.tools.build:gradle:4.0.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'

// NOTE: Do not place your application dependencies here; they belong
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
20 changes: 10 additions & 10 deletions richeditor/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
group 'com.github.kishannareshpal'
group 'com.github.quipper'

android {
compileSdkVersion 29
buildToolsVersion "28.0.3"
compileSdkVersion 29
buildToolsVersion "28.0.3"

defaultConfig {
minSdkVersion 17
targetSdkVersion 29
versionCode 1
versionName "1.3.2"
}
}
defaultConfig {
minSdkVersion 17
targetSdkVersion 29
versionCode 1
versionName "1.3.4"
}
}
5 changes: 5 additions & 0 deletions richeditor/src/main/assets/rich_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,11 @@ RE.editor.addEventListener("keyup", function(e) {
}
});
RE.editor.addEventListener("click", RE.enabledEditingItems);
RE.editor.addEventListener("paste", function(evt) {
evt.preventDefault();
var plain = Clipboard.getText();
RE.insertHTML(plain);
});


/* Helper Function */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package jp.wasabeef.richeditor;

import android.content.ClipData;
import android.content.ClipDescription;
import android.content.ClipboardManager;
import android.content.Context;

public class ClipboardInterface {
private Context context;

public ClipboardInterface(Context context) {
this.context = context;
}

@android.webkit.JavascriptInterface
public String getText() {
String plainText = "";
ClipboardManager cm = (ClipboardManager) context
.getSystemService(Context.CLIPBOARD_SERVICE);
if (cm != null) {
ClipData cd = cm.getPrimaryClip();
if (cd != null && cd.getDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN) && cd.getItemCount() > 0) {
ClipData.Item item = cd.getItemAt(0);
plainText = item.getText().toString();
}
}
return plainText;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ public RichEditor(Context context, AttributeSet attrs, int defStyleAttr) {
setWebChromeClient(new WebChromeClient());
setWebViewClient(createWebviewClient());
addJavascriptInterface(new JavascriptInterface(context), "Android");
addJavascriptInterface(new ClipboardInterface(context), "Clipboard");
loadUrl(SETUP_HTML);
applyAttributes(context, attrs);
}
Expand Down

0 comments on commit 74bce0d

Please sign in to comment.