Skip to content

Commit 17303c3

Browse files
committed
Fix: OnDraw not working issue when the line number is disabled
1 parent 511084e commit 17303c3

1 file changed

Lines changed: 16 additions & 17 deletions

File tree

codeview/src/main/java/com/amrdeveloper/codeview/CodeView.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,25 +141,24 @@ private void initEditorView() {
141141

142142
@Override
143143
protected void onDraw(Canvas canvas) {
144-
if (!enableLineNumber) return;
145-
146-
final Editable fullText = getText();
147-
final Layout layout = getLayout();
148-
final int lineCount = getLineCount();
149-
int baseline;
150-
int currentLineNumber = 1;
151-
152-
for (int i = 0; i < lineCount; ++i) {
153-
baseline = getLineBounds(i, null);
154-
if (i == 0 || fullText.charAt(layout.getLineStart(i) - 1) == '\n') {
155-
canvas.drawText(" " + currentLineNumber, lineNumberRect.left, baseline, lineNumberPaint);
156-
++currentLineNumber;
144+
if (enableLineNumber) {
145+
final Editable fullText = getText();
146+
final Layout layout = getLayout();
147+
final int lineCount = getLineCount();
148+
int baseline;
149+
int currentLineNumber = 1;
150+
151+
for (int i = 0; i < lineCount; ++i) {
152+
baseline = getLineBounds(i, null);
153+
if (i == 0 || fullText.charAt(layout.getLineStart(i) - 1) == '\n') {
154+
canvas.drawText(" " + currentLineNumber, lineNumberRect.left, baseline, lineNumberPaint);
155+
++currentLineNumber;
156+
}
157157
}
158-
}
159-
160-
int paddingLeft = 40 + (int) (Math.log10(lineCount) + 1) * 10;
161-
setPadding(paddingLeft, getPaddingTop(), getPaddingRight(), getPaddingBottom());
162158

159+
int paddingLeft = 40 + (int) (Math.log10(lineCount) + 1) * 10;
160+
setPadding(paddingLeft, getPaddingTop(), getPaddingRight(), getPaddingBottom());
161+
}
163162
super.onDraw(canvas);
164163
}
165164

0 commit comments

Comments
 (0)