fix: editor auto breaking line if line is too long
This commit is contained in:
@@ -24,6 +24,7 @@ import android.graphics.Paint;
|
|||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.support.v7.widget.AppCompatEditText;
|
import android.support.v7.widget.AppCompatEditText;
|
||||||
import android.text.Layout;
|
import android.text.Layout;
|
||||||
|
import android.text.method.ScrollingMovementMethod;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -63,6 +64,8 @@ public class CodeEditText extends AppCompatEditText {
|
|||||||
setTextColor(Color.TRANSPARENT);
|
setTextColor(Color.TRANSPARENT);
|
||||||
// 设置字体
|
// 设置字体
|
||||||
setTypeface(Typeface.MONOSPACE);
|
setTypeface(Typeface.MONOSPACE);
|
||||||
|
setMovementMethod(ScrollingMovementMethod.getInstance());
|
||||||
|
setHorizontallyScrolling(true);
|
||||||
mTheme = Theme.getDefault(getContext());
|
mTheme = Theme.getDefault(getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,4 +234,15 @@ public class CodeEditText extends AppCompatEditText {
|
|||||||
mHighlightTokens = highlightTokens;
|
mHighlightTokens = highlightTokens;
|
||||||
postInvalidate();
|
postInvalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSelection(int index) {
|
||||||
|
if (index < 0) {
|
||||||
|
index = 0;
|
||||||
|
}
|
||||||
|
if (index > getText().length()) {
|
||||||
|
index = getText().length();
|
||||||
|
}
|
||||||
|
super.setSelection(index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -164,6 +164,9 @@ public class CodeEditor extends HVScrollView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void jumpTo(int line, int col) {
|
public void jumpTo(int line, int col) {
|
||||||
|
if (line >= mCodeEditText.getLayout().getLineCount() || line < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
mCodeEditText.setSelection(mCodeEditText.getLayout().getLineStart(line) + col);
|
mCodeEditText.setSelection(mCodeEditText.getLayout().getLineStart(line) + col);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
android:id="@+id/code_edit_text"
|
android:id="@+id/code_edit_text"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:scrollbars="horizontal"
|
||||||
android:textColor="@android:color/transparent"
|
android:textColor="@android:color/transparent"
|
||||||
android:textCursorDrawable="@drawable/code_edit_text_cursor"
|
android:textCursorDrawable="@drawable/code_edit_text_cursor"
|
||||||
android:textSize="15sp"/>
|
android:textSize="15sp"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user