Update line number padding when max digits changes

This commit is contained in:
Nathan Sobo
2014-04-24 11:09:51 -06:00
parent e412371b88
commit b5f910ad06
2 changed files with 16 additions and 2 deletions

View File

@@ -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()

View File

@@ -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: '<div class="icon-right"></div>'
shouldComponentUpdate: (newProps) ->
not isEqualForProperties(newProps, @props, 'lineHeight', 'screenRow')
not isEqualForProperties(newProps, @props, 'lineHeight', 'screenRow', 'maxDigits')