mirror of
https://github.com/TonyJiangWJ/Auto.js.git
synced 2026-06-21 21:01:43 +08:00
fix: input method select all button not working
This commit is contained in:
parent
36c6b38b17
commit
72bb380776
@ -2,8 +2,8 @@
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Auto.js.iml" filepath="$PROJECT_DIR$/Auto.js.iml" />
|
||||
<module fileurl="file://E:\YiBin\AndroidStudioProjects\NoRootScriptDroid\Auto.js.iml" filepath="E:\YiBin\AndroidStudioProjects\NoRootScriptDroid\Auto.js.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/NoRootScriptDroid.iml" filepath="$PROJECT_DIR$/NoRootScriptDroid.iml" />
|
||||
<module fileurl="file://C:\Users\Stardust\Documents\AndroidProjects\Auto.js\NoRootScriptDroid.iml" filepath="C:\Users\Stardust\Documents\AndroidProjects\Auto.js\NoRootScriptDroid.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/autojs/autojs.iml" filepath="$PROJECT_DIR$/autojs/autojs.iml" />
|
||||
|
||||
@ -78,4 +78,4 @@ editor.setCursor({line: 0, ch: 0});
|
||||
|
||||
window.onload = function(){
|
||||
autojs(editor);
|
||||
}
|
||||
}
|
||||
@ -11,8 +11,11 @@ import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.ActionMode;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputConnection;
|
||||
import android.webkit.ConsoleMessage;
|
||||
import android.webkit.JavascriptInterface;
|
||||
import android.webkit.JsPromptResult;
|
||||
@ -165,12 +168,19 @@ public class CodeMirrorEditor extends FrameLayout {
|
||||
}
|
||||
|
||||
private void setupWebView() {
|
||||
mWebView = new WebView(getContext());
|
||||
mWebView = new WebView(getContext()) {
|
||||
@Override
|
||||
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
|
||||
InputConnection connection = super.onCreateInputConnection(outAttrs);
|
||||
return connection == null ? null : new MyInputConnection(connection);
|
||||
}
|
||||
};
|
||||
setupWebSettings();
|
||||
mWebView.addJavascriptInterface(mJavaScriptBridge, "__bridge__");
|
||||
addView(mWebView);
|
||||
}
|
||||
|
||||
|
||||
private void setupWebSettings() {
|
||||
WebSettings settings = mWebView.getSettings();
|
||||
settings.setBuiltInZoomControls(true);
|
||||
@ -180,8 +190,9 @@ public class CodeMirrorEditor extends FrameLayout {
|
||||
settings.setDomStorageEnabled(true);
|
||||
settings.setNeedInitialFocus(true);
|
||||
settings.setDisplayZoomControls(false);
|
||||
mWebView.setWebViewClient(new MyWebViewClient());
|
||||
mWebView.setWebChromeClient(new MyWebChromeClient());
|
||||
mWebView.setWebViewClient(new MyWebViewClient());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -531,4 +542,29 @@ public class CodeMirrorEditor extends FrameLayout {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private class MyInputConnection extends InputConnectProxy {
|
||||
|
||||
public MyInputConnection(InputConnection inputConnection) {
|
||||
super(inputConnection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendKeyEvent(KeyEvent event) {
|
||||
Log.d(LOG_TAG, "sendKeyEvent: " + event);
|
||||
return super.sendKeyEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performContextMenuAction(int id) {
|
||||
if (id == android.R.id.selectAll) {
|
||||
post(CodeMirrorEditor.this::selectAll);
|
||||
return true;
|
||||
}
|
||||
if(id == android.R.id.startSelectingText){
|
||||
evalJavaScript("editor.setSelection(editor.getCursor(), {line: editor.getCursor().line, ch: editor.getCursor().ch - 1});");
|
||||
}
|
||||
return super.performContextMenuAction(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,163 @@
|
||||
package com.stardust.scriptdroid.ui.edit;
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.inputmethod.CompletionInfo;
|
||||
import android.view.inputmethod.CorrectionInfo;
|
||||
import android.view.inputmethod.ExtractedText;
|
||||
import android.view.inputmethod.ExtractedTextRequest;
|
||||
import android.view.inputmethod.InputConnection;
|
||||
import android.view.inputmethod.InputContentInfo;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/11/4.
|
||||
*/
|
||||
|
||||
public class InputConnectProxy implements InputConnection {
|
||||
|
||||
private InputConnection mInputConnection;
|
||||
|
||||
public InputConnectProxy(InputConnection inputConnection) {
|
||||
mInputConnection = inputConnection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTextBeforeCursor(int n, int flags) {
|
||||
return mInputConnection.getTextBeforeCursor(n, flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTextAfterCursor(int n, int flags) {
|
||||
return mInputConnection.getTextAfterCursor(n, flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSelectedText(int flags) {
|
||||
return mInputConnection.getSelectedText(flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCursorCapsMode(int reqModes) {
|
||||
return mInputConnection.getCursorCapsMode(reqModes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) {
|
||||
return mInputConnection.getExtractedText(request, flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteSurroundingText(int beforeLength, int afterLength) {
|
||||
return mInputConnection.deleteSurroundingText(beforeLength, afterLength);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
@Override
|
||||
public boolean deleteSurroundingTextInCodePoints(int beforeLength, int afterLength) {
|
||||
return mInputConnection.deleteSurroundingTextInCodePoints(beforeLength, afterLength);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setComposingText(CharSequence text, int newCursorPosition) {
|
||||
return mInputConnection.setComposingText(text, newCursorPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setComposingRegion(int start, int end) {
|
||||
return mInputConnection.setComposingRegion(start, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean finishComposingText() {
|
||||
return mInputConnection.finishComposingText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean commitText(CharSequence text, int newCursorPosition) {
|
||||
return mInputConnection.commitText(text, newCursorPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean commitCompletion(CompletionInfo text) {
|
||||
return mInputConnection.commitCompletion(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean commitCorrection(CorrectionInfo correctionInfo) {
|
||||
return mInputConnection.commitCorrection(correctionInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setSelection(int start, int end) {
|
||||
return mInputConnection.setSelection(start, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performEditorAction(int editorAction) {
|
||||
return mInputConnection.performEditorAction(editorAction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performContextMenuAction(int id) {
|
||||
return mInputConnection.performContextMenuAction(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean beginBatchEdit() {
|
||||
return mInputConnection.beginBatchEdit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean endBatchEdit() {
|
||||
return mInputConnection.endBatchEdit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendKeyEvent(KeyEvent event) {
|
||||
return mInputConnection.sendKeyEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearMetaKeyStates(int states) {
|
||||
return mInputConnection.clearMetaKeyStates(states);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean reportFullscreenMode(boolean enabled) {
|
||||
return mInputConnection.reportFullscreenMode(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performPrivateCommand(String action, Bundle data) {
|
||||
return mInputConnection.performPrivateCommand(action, data);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public boolean requestCursorUpdates(int cursorUpdateMode) {
|
||||
return mInputConnection.requestCursorUpdates(cursorUpdateMode);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
@Override
|
||||
public Handler getHandler() {
|
||||
return mInputConnection.getHandler();
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
@Override
|
||||
public void closeConnection() {
|
||||
mInputConnection.closeConnection();
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
|
||||
@Override
|
||||
public boolean commitContent(@NonNull InputContentInfo inputContentInfo, int flags, @Nullable Bundle opts) {
|
||||
return mInputConnection.commitContent(inputContentInfo, flags, opts);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user