提升编辑器的使用体验
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
package org.autojs.autojs.model.autocomplete;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2018/2/3.
|
||||
*/
|
||||
public class CodeCompletion {
|
||||
|
||||
private final String mHint;
|
||||
private final String mUrl;
|
||||
private final String mInsertText;
|
||||
private final int mInsertPos;
|
||||
|
||||
public CodeCompletion(String hint, String url, int insertPos) {
|
||||
mHint = hint;
|
||||
mUrl = url;
|
||||
mInsertPos = insertPos;
|
||||
mInsertText = null;
|
||||
}
|
||||
|
||||
public CodeCompletion(String hint, String url, String insertText) {
|
||||
mHint = hint;
|
||||
mUrl = url;
|
||||
mInsertText = insertText;
|
||||
mInsertPos = -1;
|
||||
}
|
||||
|
||||
public String getHint() {
|
||||
return mHint;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return mUrl;
|
||||
}
|
||||
|
||||
public String getInsertText() {
|
||||
if (mInsertText != null)
|
||||
return mInsertText;
|
||||
if (mInsertPos == 0) {
|
||||
return mHint;
|
||||
}
|
||||
return mHint.substring(mInsertPos);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.autojs.autojs.model.autocomplete
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2018/2/3.
|
||||
*/
|
||||
class CodeCompletion {
|
||||
val hint: String
|
||||
val url: String?
|
||||
private val mInsertText: String?
|
||||
private val mInsertPos: Int
|
||||
|
||||
constructor(hint: String, url: String?, insertPos: Int) {
|
||||
this.hint = hint
|
||||
this.url = url
|
||||
mInsertPos = insertPos
|
||||
mInsertText = null
|
||||
}
|
||||
|
||||
constructor(hint: String, url: String, insertText: String?) {
|
||||
this.hint = hint
|
||||
this.url = url
|
||||
mInsertText = insertText
|
||||
mInsertPos = -1
|
||||
}
|
||||
|
||||
val insertText: String
|
||||
get() {
|
||||
if (mInsertText != null) return mInsertText
|
||||
return if (mInsertPos == 0) {
|
||||
hint
|
||||
} else hint.substring(mInsertPos)
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package org.autojs.autojs.model.autocomplete;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/9/27.
|
||||
*/
|
||||
public class CodeCompletions {
|
||||
|
||||
|
||||
private final int mFrom;
|
||||
private final List<CodeCompletion> mCompletions;
|
||||
|
||||
public CodeCompletions(int cursor, List<CodeCompletion> completions) {
|
||||
mFrom = cursor;
|
||||
mCompletions = completions;
|
||||
}
|
||||
|
||||
public static CodeCompletions just(List<String> hints) {
|
||||
List<CodeCompletion> completions = new ArrayList<>(hints.size());
|
||||
for (String hint : hints) {
|
||||
completions.add(new CodeCompletion(hint, null, 0));
|
||||
}
|
||||
return new CodeCompletions(-1, completions);
|
||||
}
|
||||
|
||||
public int getFrom() {
|
||||
return mFrom;
|
||||
}
|
||||
|
||||
|
||||
public int size() {
|
||||
return mCompletions.size();
|
||||
}
|
||||
|
||||
public String getHint(int position) {
|
||||
return mCompletions.get(position).getHint();
|
||||
}
|
||||
|
||||
public CodeCompletion get(int pos) {
|
||||
return mCompletions.get(pos);
|
||||
}
|
||||
|
||||
public String getUrl(int pos) {
|
||||
return mCompletions.get(pos).getUrl();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.autojs.autojs.model.autocomplete
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/9/27.
|
||||
*/
|
||||
class CodeCompletions(val from: Int, private val mCompletions: List<CodeCompletion>) {
|
||||
fun size(): Int {
|
||||
return mCompletions.size
|
||||
}
|
||||
|
||||
fun getHint(position: Int): String {
|
||||
return mCompletions[position].hint
|
||||
}
|
||||
|
||||
operator fun get(pos: Int): CodeCompletion {
|
||||
return mCompletions[pos]
|
||||
}
|
||||
|
||||
fun getUrl(pos: Int): String? {
|
||||
return mCompletions[pos].url
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun just(hints: List<String?>): CodeCompletions {
|
||||
val completions: MutableList<CodeCompletion> = ArrayList(hints.size)
|
||||
for (hint in hints) {
|
||||
completions.add(CodeCompletion(hint!!, null, 0))
|
||||
}
|
||||
return CodeCompletions(-1, completions)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,10 +9,10 @@ import java.util.Arrays;
|
||||
public class Symbols {
|
||||
|
||||
private static final CodeCompletions sSymbols = CodeCompletions.just(Arrays.asList(
|
||||
",", ".", "=", ";", "\"", "'", "-", "_",
|
||||
",", ".", "=", ";", "\"", "'", "/", "_",
|
||||
"(", ")", "[", "]", "{", "}", "<", ">",
|
||||
"+", "*", "?", "$", "#", "@", "`",
|
||||
"/", "\\", "&", "|", "!", "%", "×", "÷",
|
||||
"-", "\\", "&", "|", "!", "%", "×", "÷",
|
||||
"∈", "∩", "∪", "∉", "⊙", "∅", "¥", "€",
|
||||
"°", "℃", "∵", "∴", "±", "≠", "≈",
|
||||
"α", "β", "γ", "λ", "μ", "π", "σ", "ω",
|
||||
|
||||
@@ -285,7 +285,12 @@ open class EditorView : FrameLayout, OnHintClickListener, ClickCallback, Toolbar
|
||||
.setFunctionsView(mFunctionsKeyboard)
|
||||
.setEditView(editor!!.codeEditText)
|
||||
.build()
|
||||
mFunctionsKeyboard!!.setClickCallback(this)
|
||||
//todo:不清楚作用,暂时注释掉
|
||||
//mFunctionsKeyboard!!.setClickCallback(this)
|
||||
mShowFunctionsButton!!.setOnLongClickListener {
|
||||
editor!!.beautifyCode()
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
private fun setUpInputMethodEnhancedBar() {
|
||||
@@ -321,7 +326,7 @@ open class EditorView : FrameLayout, OnHintClickListener, ClickCallback, Toolbar
|
||||
mAutoCompletion!!.onCursorChange(line, cursor)
|
||||
}
|
||||
|
||||
fun setTheme(theme: Theme?) {
|
||||
private fun setTheme(theme: Theme?) {
|
||||
theme?.let {
|
||||
mEditorTheme = it
|
||||
editor!!.setTheme(it)
|
||||
@@ -575,11 +580,19 @@ open class EditorView : FrameLayout, OnHintClickListener, ClickCallback, Toolbar
|
||||
|
||||
override fun onHintClick(completions: CodeCompletions, pos: Int) {
|
||||
val completion = completions[pos]
|
||||
editor!!.insert(completion.insertText)
|
||||
//todo:增加行注释
|
||||
if (completion.insertText=="/") {
|
||||
editor!!.commentLine()
|
||||
} else editor!!.insert(completion.insertText)
|
||||
}
|
||||
|
||||
override fun onHintLongClick(completions: CodeCompletions, pos: Int) {
|
||||
val completion = completions[pos]
|
||||
//todo:增加块注释
|
||||
if (completion.insertText=="/") {
|
||||
editor!!.commentBlock()
|
||||
return
|
||||
}
|
||||
if (completion.url == null) return
|
||||
showManual(completion.url, completion.hint)
|
||||
}
|
||||
|
||||
@@ -403,11 +403,14 @@ public class CodeEditor extends HVScrollView {
|
||||
|
||||
public void beautifyCode() {
|
||||
setProgress(true);
|
||||
int pos = mCodeEditText.getSelectionStart();
|
||||
mJsBeautifier.beautify(mCodeEditText.getText().toString(), new JsBeautifier.Callback() {
|
||||
@Override
|
||||
public void onSuccess(String beautifiedCode) {
|
||||
setProgress(false);
|
||||
mCodeEditText.setText(beautifiedCode);
|
||||
//格式化后恢复光标位置
|
||||
mCodeEditText.setSelection(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -418,6 +421,43 @@ public class CodeEditor extends HVScrollView {
|
||||
});
|
||||
}
|
||||
|
||||
public void commentLine() {
|
||||
//如果没有选中,则添加文本/,否则选中的行前加//
|
||||
String selectionText = getSelectionRaw();
|
||||
if (selectionText.equals("")) {
|
||||
insert("/");
|
||||
} else {
|
||||
String[] lines = selectionText.split("\\n");
|
||||
StringBuilder commentedText = new StringBuilder();
|
||||
//处理取消注释
|
||||
if (lines[0].startsWith("//")) {
|
||||
for (String line : lines) {
|
||||
commentedText.append(line.substring(2)).append("\n");
|
||||
}
|
||||
} else {
|
||||
for (String line : lines) {
|
||||
commentedText.append("//").append(line).append("\n");
|
||||
}
|
||||
}
|
||||
mReplacement = commentedText.toString().replaceAll("\\n$", "");
|
||||
replaceSelection();
|
||||
}
|
||||
}
|
||||
|
||||
public void commentBlock() {
|
||||
String selectionText = getSelectionRaw();
|
||||
if (!selectionText.isEmpty()) {
|
||||
String regex = "/\\*([^*]|\\*+[^*/])*\\*/";
|
||||
if (selectionText.matches(regex)) {
|
||||
// 取消块注释
|
||||
mReplacement = selectionText.substring(2, selectionText.length() - 2);
|
||||
} else {
|
||||
// 增加块注释
|
||||
mReplacement = "/*" + selectionText + "*/";
|
||||
}
|
||||
replaceSelection();
|
||||
}
|
||||
}
|
||||
|
||||
public void insert(String insertText) {
|
||||
int selection = Math.max(mCodeEditText.getSelectionStart(), 0);
|
||||
@@ -437,13 +477,17 @@ public class CodeEditor extends HVScrollView {
|
||||
return mCodeEditText.getText().toString();
|
||||
}
|
||||
|
||||
public Observable<String> getSelection() {
|
||||
public String getSelectionRaw() {
|
||||
int s = mCodeEditText.getSelectionStart();
|
||||
int e = mCodeEditText.getSelectionEnd();
|
||||
if (s == e) {
|
||||
return Observable.just("");
|
||||
return "";
|
||||
}
|
||||
return Observable.just(mCodeEditText.getText().toString().substring(s, e));
|
||||
return mCodeEditText.getText().toString().substring(s, e);
|
||||
}
|
||||
|
||||
public Observable<String> getSelection() {
|
||||
return Observable.just(getSelectionRaw());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -63,15 +63,16 @@
|
||||
android:layout_alignParentBottom="true" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/functions"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="35dp"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:background="?selectableItemBackgroundBorderless"
|
||||
android:padding="6dp"
|
||||
android:src="@drawable/ic_ali_fx"
|
||||
app:tint="#222329" />
|
||||
android:id="@+id/functions"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="35dp"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:background="?selectableItemBackgroundBorderless"
|
||||
android:contentDescription="@string/fun"
|
||||
android:padding="6dp"
|
||||
android:src="@drawable/ic_ali_fx"
|
||||
app:tint="#222329" />
|
||||
|
||||
<org.autojs.autojs.ui.edit.completion.CodeCompletionBar
|
||||
android:id="@+id/code_completion_bar"
|
||||
|
||||
@@ -880,6 +880,7 @@
|
||||
<string name="error_colon_must_follow_a_valid_ip_address">Colon must follow a valid IP address</string>
|
||||
<string name="error_repeated_dot_symbol">Repeated dot symbol</string>
|
||||
<string name="error_repeated_colon_symbol">Repeated colon symbol</string>
|
||||
<string name="fun">函数</string>
|
||||
|
||||
<plurals name="text_items_total_sum">
|
||||
<item quantity="one">Total: %d item</item>
|
||||
|
||||
@@ -128,6 +128,7 @@ buildscript {
|
||||
}
|
||||
|
||||
dependencies /* Android/Kotlin Gradle Plugin. */ {
|
||||
classpath("com.android.tools.build:gradle:7.1.2")
|
||||
val android = gradlePluginVersionList[platformType]!!["android"]!!
|
||||
val kotlin = gradlePluginVersionList[platformType]!!["kotlin"]!!
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#Tue Jul 11 00:23:06 CST 2023
|
||||
BUILD_TIME=1689006186217
|
||||
#Tue Jul 11 20:02:39 CST 2023
|
||||
BUILD_TIME=1689076959792
|
||||
COMPILE_SDK_VERSION=33
|
||||
JAVA_VERSION=20
|
||||
MIN_SDK_VERSION=24
|
||||
TARGET_SDK_VERSION=33
|
||||
VERSION_BUILD=2010
|
||||
VERSION_BUILD=2015
|
||||
VERSION_NAME=6.3.2
|
||||
|
||||
Reference in New Issue
Block a user