diff --git a/spec/editor-component-spec.coffee b/spec/editor-component-spec.coffee index 812bfcf74..05a5b89c9 100644 --- a/spec/editor-component-spec.coffee +++ b/spec/editor-component-spec.coffee @@ -188,6 +188,20 @@ describe "EditorComponent", -> expect(lines[4].textContent).toBe "#{nbsp}3" expect(lines[5].textContent).toBe "#{nbsp}•" + it "pads line numbers to be right justified based on the maximum number of line number digits", -> + editor.getBuffer().setText([1..10].join('\n')) + lineNumberNodes = toArray(node.querySelectorAll('.line-number')) + + for node, i in lineNumberNodes[0..8] + expect(node.textContent).toBe "#{nbsp}#{i + 1}" + expect(lineNumberNodes[9].textContent).toBe '10' + + # Removes padding when the max number of digits goes down + editor.getBuffer().delete([[1, 0], [2, 0]]) + lineNumberNodes = toArray(node.querySelectorAll('.line-number')) + for node, i in lineNumberNodes + expect(node.textContent).toBe "#{i + 1}" + describe "cursor rendering", -> it "renders the currently visible cursors", -> cursor1 = editor.getCursor() diff --git a/src/gutter-component.coffee b/src/gutter-component.coffee index 948860180..ef3529e79 100644 --- a/src/gutter-component.coffee +++ b/src/gutter-component.coffee @@ -17,7 +17,7 @@ GutterComponent = React.createClass [startRow, endRow] = renderedRowRange charWidth = editor.getDefaultCharWidth() lineHeight = editor.getLineHeight() - maxDigits = editor.getLastBufferRow().toString().length + maxDigits = editor.getScreenLineCount().toString().length style = width: charWidth * (maxDigits + 1.5) height: scrollHeight @@ -76,4 +76,4 @@ LineNumberComponent = React.createClass iconDivHTML: '
' shouldComponentUpdate: (newProps) -> - not isEqualForProperties(newProps, @props, 'lineHeight', 'screenRow') + not isEqualForProperties(newProps, @props, 'lineHeight', 'screenRow', 'maxDigits')