fix: editor cannot scroll horizontally if editor's height < parent's height
This commit is contained in:
@@ -24,11 +24,13 @@ import android.graphics.Paint;
|
||||
import android.graphics.Typeface;
|
||||
import android.support.v7.widget.AppCompatEditText;
|
||||
import android.text.Layout;
|
||||
import android.text.method.ScrollingMovementMethod;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.TimingLogger;
|
||||
import android.view.Gravity;
|
||||
|
||||
import com.stardust.scriptdroid.BuildConfig;
|
||||
import com.stardust.scriptdroid.ui.edit.theme.Theme;
|
||||
|
||||
/**
|
||||
@@ -39,7 +41,8 @@ public class CodeEditText extends AppCompatEditText {
|
||||
|
||||
|
||||
static final String LOG_TAG = "CodeEditText";
|
||||
private static final boolean DEBUG = true;
|
||||
private static final boolean DEBUG = BuildConfig.DEBUG;
|
||||
|
||||
// 文字范围
|
||||
protected HVScrollView mParentScrollView;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.stardust.scriptdroid.ui.edit.editor;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
@@ -64,7 +65,7 @@ public class CodeEditor extends HVScrollView {
|
||||
|
||||
|
||||
private void init() {
|
||||
setFillViewport(true);
|
||||
//setFillViewport(true);
|
||||
inflate(getContext(), R.layout.code_editor, this);
|
||||
mCodeEditText = (CodeEditText) findViewById(R.id.code_edit_text);
|
||||
mTextViewRedoUndo = new TextViewRedoUndo(mCodeEditText);
|
||||
@@ -152,7 +153,7 @@ public class CodeEditor extends HVScrollView {
|
||||
return mTextViewRedoUndo.canUndo();
|
||||
}
|
||||
|
||||
public boolean canRedo(){
|
||||
public boolean canRedo() {
|
||||
return mTextViewRedoUndo.canRedo();
|
||||
}
|
||||
|
||||
@@ -313,4 +314,15 @@ public class CodeEditor extends HVScrollView {
|
||||
mTextViewRedoUndo.clearHistory();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
int codeWidth = getWidth() - getPaddingLeft() - getPaddingRight();
|
||||
int codeHeight = getHeight() - getPaddingTop() - getPaddingBottom();
|
||||
if (mCodeEditText.getMinWidth() != codeWidth || mCodeEditText.getMinWidth() != codeWidth) {
|
||||
mCodeEditText.setMinWidth(codeWidth);
|
||||
mCodeEditText.setMinHeight(codeHeight);
|
||||
invalidate();
|
||||
}
|
||||
super.onDraw(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,7 +400,7 @@ public class HVScrollView extends FrameLayout {
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
/*
|
||||
* This method JUST determines whether we want to intercept the motion.
|
||||
* This method JUST determines whether we want to intercept the motion.
|
||||
* If we return true, onMotionEvent will be called and we do the actual
|
||||
* scrolling there.
|
||||
*/
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
<com.stardust.scriptdroid.ui.edit.editor.CodeEditText
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/code_edit_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:scrollHorizontally="true"
|
||||
android:textColor="@android:color/transparent"
|
||||
android:textCursorDrawable="@drawable/code_edit_text_cursor"
|
||||
android:textSize="15sp"/>
|
||||
|
||||
Reference in New Issue
Block a user