@@ -132,22 +132,25 @@ private void initEditorView() {
132132
133133 @ Override
134134 protected void onDraw (Canvas canvas ) {
135- if (enableLineNumber ) {
136- int baseline ;
137- int lineCount = getLineCount ();
138- int lineNumber = 1 ;
139-
140- for (int i = 0 ; i < lineCount ; ++i ) {
141- baseline = getLineBounds (i , null );
142- if (i == 0 || getText ().charAt (getLayout ().getLineStart (i ) - 1 ) == '\n' ) {
143- canvas .drawText (String .format (Locale .ENGLISH , " %d" , lineNumber ), lineNumberRect .left , baseline , lineNumberPaint );
144- ++lineNumber ;
145- }
135+ if (!enableLineNumber ) return ;
136+
137+ final Editable fullText = getText ();
138+ final Layout layout = getLayout ();
139+ final int lineCount = getLineCount ();
140+ int baseline ;
141+ int currentLineNumber = 1 ;
142+
143+ for (int i = 0 ; i < lineCount ; ++i ) {
144+ baseline = getLineBounds (i , null );
145+ if (i == 0 || fullText .charAt (layout .getLineStart (i ) - 1 ) == '\n' ) {
146+ canvas .drawText (" " + currentLineNumber , lineNumberRect .left , baseline , lineNumberPaint );
147+ ++currentLineNumber ;
146148 }
147-
148- int paddingLeft = 40 + (int ) (Math .log10 (lineCount ) + 1 ) * 10 ;
149- setPadding (paddingLeft , getPaddingTop (), getPaddingRight (), getPaddingBottom ());
150149 }
150+
151+ int paddingLeft = 40 + (int ) (Math .log10 (lineCount ) + 1 ) * 10 ;
152+ setPadding (paddingLeft , getPaddingTop (), getPaddingRight (), getPaddingBottom ());
153+
151154 super .onDraw (canvas );
152155 }
153156
0 commit comments