     @highlightCursorLine()
 
   calculateWidth: ->
-    width = @editor().getLineCount().toString().length * @editor().charWidth
-    if width != @cachedWidth
-      @cachedWidth = width
-      @lineNumbers.width(width)
+    highestNumberWidth = @editor().getLineCount().toString().length * @editor().charWidth
+    if highestNumberWidth != @highestNumberWidth
+      @highestNumberWidth = highestNumberWidth
+      @lineNumbers.width(highestNumberWidth + @lineNumberPadding())
       @widthChanged?(@outerWidth())
 
   highlightCursorLine: ->
     cursorScreenRow = @editor().getCursorScreenPosition().row
     screenRowIndex = cursorScreenRow - @firstScreenRow
-    @find('.line-number.cursor-line-number').removeClass('cursor-line-number')
+    @find(".line-number.cursor-line-number").removeClass('cursor-line-number')
     @find(".line-number:eq(#{screenRowIndex})").addClass('cursor-line-number')

      @div outlet: 'lineNumbers', class: 'line-numbers'

  firstScreenRow: -1

  afterAttach: (onDom) ->
    @editor()?.on 'cursor-move', => @highlightCursorLine()

  editor: ->
    @parentView

  renderLineNumbers: (startScreenRow, endScreenRow) ->
    @firstScreenRow = startScreenRow

{View, $$, $$$} = require 'space-pen'

$ = require 'jquery'
_ = require 'underscore'
