Skip to content

Commit 90f1787

Browse files
committed
draw all line when scroll bar is not enable
1 parent 1d49ae5 commit 90f1787

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

app/src/main/res/layout/list_item_theme.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
34
android:layout_width="match_parent"
45
android:layout_height="wrap_content"
5-
xmlns:app="http://schemas.android.com/apk/res-auto"
66
android:layout_marginTop="4dp"
77
android:orientation="vertical">
88

@@ -24,16 +24,16 @@
2424
android:id="@+id/btn_select"
2525
android:layout_width="wrap_content"
2626
android:layout_height="wrap_content"
27-
android:typeface="monospace"
28-
app:srcCompat="@drawable/baseline_check_24"
29-
android:text="Select" />
27+
android:text="Select"
28+
app:srcCompat="@drawable/baseline_check_24" />
3029

3130
</LinearLayout>
3231

3332
<com.duy.ide.editor.view.EditAreaView2
3433
android:id="@+id/editor_view"
3534
android:layout_width="match_parent"
36-
android:layout_height="wrap_content">
35+
android:layout_height="wrap_content"
36+
android:typeface="monospace">
3737

3838
</com.duy.ide.editor.view.EditAreaView2>
3939
</LinearLayout>

libeditor/src/main/java/com/duy/ide/editor/text/LineManager.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public int getFirstVisibleVirtualLine() {
5858
if (layout == null) {
5959
return 0;
6060
}
61+
boolean verticalScrollBarEnabled = mEditText.isVerticalScrollBarEnabled();
62+
if (!verticalScrollBarEnabled) {
63+
return 0;
64+
}
65+
6166
int lineCount = layout.getLineCount();
6267
int line = (int) (mEditText.getScrollY() / ((float) layout.getHeight()) * lineCount);
6368
line = Math.max(0, Math.min(line, lineCount - 1));
@@ -73,8 +78,13 @@ public int getLastVisibleVirtualLine() {
7378
if (layout == null) {
7479
return 0;
7580
}
76-
mEditText.getGlobalVisibleRect(BOUND);
7781
int lineCount = mEditText.getLineCount();
82+
boolean verticalScrollBarEnabled = mEditText.isVerticalScrollBarEnabled();
83+
if (!verticalScrollBarEnabled) {
84+
return lineCount - 1;
85+
}
86+
87+
mEditText.getGlobalVisibleRect(BOUND);
7888
int line = (int) ((mEditText.getScrollY() + BOUND.height()) / ((float) layout.getHeight()) * lineCount);
7989
line = Math.max(0, Math.min(line, lineCount - 1));
8090
return line;

libeditor/src/main/java/com/duy/ide/editor/view/EditAreaView2.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ private void init(Context context) {
125125
public void setText(CharSequence text, BufferType type) {
126126
super.setText(text, type);
127127
mNeedUpdateLineNumber = true;
128+
mPreLineCount = -1;
128129
}
129130

130131
@Override
@@ -153,7 +154,6 @@ public EditorTheme getEditorTheme() {
153154
protected void onDraw(Canvas canvas) {
154155
super.onDraw(canvas);
155156

156-
157157
drawLineNumber(canvas);
158158
}
159159

@@ -295,9 +295,10 @@ private void drawLineNumber(Canvas canvas) {
295295

296296
List<TextLineNumber.LineInfo> lines = mLineManager.getTextLineNumber().getLines();
297297
int x = mLayoutContext.getLineNumberX() + getScrollX();
298+
int paddingTop = getPaddingTop();
298299
Paint paint = mLayoutContext.getGutterForegroundPaint();
299300
for (TextLineNumber.LineInfo line : lines) {
300-
canvas.drawText(line.getText(), x, line.getY(), paint);
301+
canvas.drawText(line.getText(), x, line.getY() + paddingTop, paint);
301302
}
302303
}
303304

@@ -368,7 +369,7 @@ public void setTextSize(int unit, float size) {
368369
@Override
369370
protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
370371
super.onTextChanged(text, start, lengthBefore, lengthAfter);
371-
setNeedUpdateLineNumber(true);
372+
updateLineNumberCount(start);
372373
}
373374

374375
/**
@@ -400,7 +401,7 @@ private void updateLayoutContext() {
400401
private void updateGutterSize() {
401402
int numberPadding = SysUtils.dpToPixels(getContext(), 2);
402403

403-
float textWidth = mLayoutContext.getGutterForegroundPaint().measureText(" ");
404+
float textWidth = mLayoutContext.getGutterForegroundPaint().measureText("8");
404405
//plus 1 for some case: log(100) = 2, but we need 3
405406
double columnCount = Math.ceil(Math.log10(mLineManager.getRealLineCount() + 1)) + 1;
406407
mLayoutContext.setGutterWidth(((int) (textWidth * columnCount)) + numberPadding * 2/*Left and right*/);
@@ -411,8 +412,4 @@ private void updateGutterSize() {
411412
setPadding(newPaddingLeft, getPaddingTop(), getPaddingRight(), getPaddingBottom());
412413
}
413414

414-
public void setNeedUpdateLineNumber(boolean needUpdateLineNumber) {
415-
mNeedUpdateLineNumber = needUpdateLineNumber;
416-
mPreLineCount = -1;
417-
}
418415
}

0 commit comments

Comments
 (0)