feat(ui): supports touching gutter to set breakpoint
This commit is contained in:
@@ -33,7 +33,7 @@ public class CodeEvaluateDialogBuilder extends ThemeColorMaterialDialogBuilder {
|
|||||||
customView(view, true);
|
customView(view, true);
|
||||||
mResult = view.findViewById(R.id.result);
|
mResult = view.findViewById(R.id.result);
|
||||||
mCode = view.findViewById(R.id.code);
|
mCode = view.findViewById(R.id.code);
|
||||||
positiveText(R.string.text_run);
|
positiveText(R.string.text_execute);
|
||||||
negativeText(R.string.text_close);
|
negativeText(R.string.text_close);
|
||||||
autoDismiss(false);
|
autoDismiss(false);
|
||||||
onNegative((dialog, which) -> dialog.dismiss());
|
onNegative((dialog, which) -> dialog.dismiss());
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import android.util.AttributeSet;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.TimingLogger;
|
import android.util.TimingLogger;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
import org.autojs.autojs.ui.edit.theme.Theme;
|
import org.autojs.autojs.ui.edit.theme.Theme;
|
||||||
import org.autojs.autojs.ui.edit.theme.TokenMapping;
|
import org.autojs.autojs.ui.edit.theme.TokenMapping;
|
||||||
@@ -270,7 +271,7 @@ public class CodeEditText extends AppCompatEditText {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Layout layout = getLayout();
|
Layout layout = getLayout();
|
||||||
if(layout == null){
|
if (layout == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int lineTop = layout.getLineTop(line);
|
int lineTop = layout.getLineTop(line);
|
||||||
@@ -390,7 +391,7 @@ public class CodeEditText extends AppCompatEditText {
|
|||||||
return;
|
return;
|
||||||
String line = text.subSequence(lineStart, lineEnd).toString();
|
String line = text.subSequence(lineStart, lineEnd).toString();
|
||||||
int cursor = sel - lineStart;
|
int cursor = sel - lineStart;
|
||||||
for(CodeEditor.CursorChangeCallback callback : mCursorChangeCallbacks){
|
for (CodeEditor.CursorChangeCallback callback : mCursorChangeCallbacks) {
|
||||||
callback.onCursorChange(line, cursor);
|
callback.onCursorChange(line, cursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -404,7 +405,6 @@ public class CodeEditText extends AppCompatEditText {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void updateHighlightTokens(JavaScriptHighlighter.HighlightTokens highlightTokens) {
|
public void updateHighlightTokens(JavaScriptHighlighter.HighlightTokens highlightTokens) {
|
||||||
mHighlightTokens = highlightTokens;
|
mHighlightTokens = highlightTokens;
|
||||||
postInvalidate();
|
postInvalidate();
|
||||||
@@ -451,4 +451,39 @@ public class CodeEditText extends AppCompatEditText {
|
|||||||
super.onRestoreInstanceState(superData);
|
super.onRestoreInstanceState(superData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int mTouchedLine = -1;
|
||||||
|
private boolean mTouchValid = true;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
|
//如果行号区域被按下
|
||||||
|
if (event.getAction() == MotionEvent.ACTION_DOWN && event.getX() < getPaddingLeft()) {
|
||||||
|
//则计算当前行,如果行号有效,记录起来
|
||||||
|
int line = getLayout().getLineForVertical((int) event.getY());
|
||||||
|
if (line >= 0) {
|
||||||
|
mTouchedLine = line;
|
||||||
|
mTouchValid = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (mTouchedLine >= 0) {
|
||||||
|
//如果之前已经是行号区域被按下了,则之后的事件也要处理
|
||||||
|
//如果之后的触摸区域超出行号区域,或者触摸的行号与第一次触摸事件时的不同,则这一系列的触摸无效
|
||||||
|
if (event.getX() >= getPaddingLeft() || (getLayout().getLineForVertical((int) event.getY()) != mTouchedLine)) {
|
||||||
|
mTouchValid = false;
|
||||||
|
}
|
||||||
|
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||||
|
//当触摸有效时,对那一行设置断点或取消断点
|
||||||
|
if (mTouchValid) {
|
||||||
|
if (mBreakpoints.remove(mTouchedLine) == null) {
|
||||||
|
mBreakpoints.put(mTouchedLine, new CodeEditor.Breakpoint(mTouchedLine));
|
||||||
|
}
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
mTouchedLine = -1;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onTouchEvent(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.autojs.autojs.ui.edit.editor;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
import android.os.Parcelable;
|
||||||
import android.text.Layout;
|
import android.text.Layout;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
@@ -71,4 +72,10 @@ public class LayoutHelper {
|
|||||||
return low;
|
return low;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getVisibleLineAt(Layout layout, float x, float y) {
|
||||||
|
if(layout == null) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,15 +7,15 @@
|
|||||||
<com.stardust.theme.widget.ThemeColorTextView
|
<com.stardust.theme.widget.ThemeColorTextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingLeft="8dp"
|
android:layout_marginLeft="8dp"
|
||||||
android:text="@string/text_code"
|
android:text="@string/text_code"
|
||||||
android:textSize="14sp"/>
|
android:textSize="14sp"/>
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/code"
|
android:id="@+id/code"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:paddingBottom="8dp"
|
android:layout_marginBottom="8dp"
|
||||||
android:paddingLeft="8dp"
|
android:layout_marginLeft="8dp"
|
||||||
android:textSize="15sp"
|
android:textSize="15sp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textColor="@android:color/primary_text_light"/>
|
android:textColor="@android:color/primary_text_light"/>
|
||||||
@@ -23,14 +23,14 @@
|
|||||||
<com.stardust.theme.widget.ThemeColorTextView
|
<com.stardust.theme.widget.ThemeColorTextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingBottom="8dp"
|
android:layout_marginBottom="8dp"
|
||||||
android:paddingLeft="8dp"
|
android:layout_marginLeft="8dp"
|
||||||
android:text="@string/text_result"
|
android:text="@string/text_result"
|
||||||
android:textSize="14sp"/>
|
android:textSize="14sp"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/result"
|
android:id="@+id/result"
|
||||||
android:paddingLeft="8dp"
|
android:layout_marginLeft="8dp"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textColor="#727377"
|
android:textColor="#727377"
|
||||||
|
|||||||
@@ -378,4 +378,5 @@
|
|||||||
<string name="text_code">代码</string>
|
<string name="text_code">代码</string>
|
||||||
<string name="text_result">结果</string>
|
<string name="text_result">结果</string>
|
||||||
<string name="text_close">关闭</string>
|
<string name="text_close">关闭</string>
|
||||||
|
<string name="text_execute">执行</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user