Use padding-top/bottom rather than spacer divs in lines and gutter

It creates a simpler DOM structure.
This commit is contained in:
Nathan Sobo
2014-04-16 13:56:24 -06:00
parent 3a42346e5e
commit 6607f99c6c
3 changed files with 24 additions and 30 deletions

View File

@@ -49,14 +49,14 @@ describe "EditorComponent", ->
expect(node.querySelector('.scroll-view-content').style['-webkit-transform']).toBe "translate(0px, #{-2.5 * lineHeightInPixels}px)"
lines = node.querySelectorAll('.line')
expect(lines.length).toBe 6
expect(lines[0].textContent).toBe editor.lineForScreenRow(2).text
expect(lines[5].textContent).toBe editor.lineForScreenRow(7).text
lineNodes = node.querySelectorAll('.line')
expect(lineNodes.length).toBe 6
expect(lineNodes[0].textContent).toBe editor.lineForScreenRow(2).text
expect(lineNodes[5].textContent).toBe editor.lineForScreenRow(7).text
spacers = node.querySelectorAll('.lines .spacer')
expect(spacers[0].offsetHeight).toBe 2 * lineHeightInPixels
expect(spacers[1].offsetHeight).toBe (editor.getScreenLineCount() - 8) * lineHeightInPixels
linesNode = node.querySelector('.lines')
expect(linesNode.style.paddingTop).toBe 2 * lineHeightInPixels + 'px'
expect(linesNode.style.paddingBottom).toBe (editor.getScreenLineCount() - 8) * lineHeightInPixels + 'px'
describe "when indent guides are enabled", ->
beforeEach ->
@@ -134,14 +134,14 @@ describe "EditorComponent", ->
expect(node.querySelector('.line-numbers').style['-webkit-transform']).toBe "translateY(#{-2.5 * lineHeightInPixels}px)"
lines = node.querySelectorAll('.line-number')
expect(lines.length).toBe 6
expect(lines[0].textContent).toBe "#{nbsp}3"
expect(lines[5].textContent).toBe "#{nbsp}8"
lineNumberNodes = node.querySelectorAll('.line-number')
expect(lineNumberNodes.length).toBe 6
expect(lineNumberNodes[0].textContent).toBe "#{nbsp}3"
expect(lineNumberNodes[5].textContent).toBe "#{nbsp}8"
spacers = node.querySelectorAll('.line-numbers .spacer')
expect(spacers[0].offsetHeight).toBe 2 * lineHeightInPixels
expect(spacers[1].offsetHeight).toBe (editor.getScreenLineCount() - 8) * lineHeightInPixels
lineNumbersNode = node.querySelector('.line-numbers')
expect(lineNumbersNode.style.paddingTop).toBe 2 * lineHeightInPixels + 'px'
expect(lineNumbersNode.style.paddingBottom).toBe (editor.getScreenLineCount() - 8) * lineHeightInPixels + 'px'
it "renders • characters for soft-wrapped lines", ->
editor.setSoftWrap(true)

View File

@@ -12,12 +12,12 @@ GutterComponent = React.createClass
{editor, visibleRowRange, scrollTop} = @props
[startRow, endRow] = visibleRowRange
lineHeightInPixels = editor.getLineHeight()
precedingHeight = startRow * lineHeightInPixels
followingHeight = (editor.getScreenLineCount() - endRow) * lineHeightInPixels
maxDigits = editor.getLastBufferRow().toString().length
style =
height: editor.getScrollHeight()
WebkitTransform: "translateY(#{-scrollTop}px)"
paddingTop: startRow * lineHeightInPixels
paddingBottom: (editor.getScreenLineCount() - endRow) * lineHeightInPixels
wrapCount = 0
lineNumbers = []
@@ -35,11 +35,8 @@ GutterComponent = React.createClass
lastBufferRow = bufferRow
div className: 'gutter',
div className: 'line-numbers', style: style, [
div className: 'spacer', key: 'top-spacer', style: {height: precedingHeight}
lineNumbers...
div className: 'spacer', key: 'bottom-spacer', style: {height: followingHeight}
]
div className: 'line-numbers', style: style,
lineNumbers
componentWillUnmount: ->
@unsubscribe()

View File

@@ -14,15 +14,12 @@ LinesComponent = React.createClass
{editor, visibleRowRange, showIndentGuide} = @props
[startRow, endRow] = visibleRowRange
lineHeightInPixels = editor.getLineHeight()
precedingHeight = startRow * lineHeightInPixels
followingHeight = (editor.getScreenLineCount() - endRow) * lineHeightInPixels
paddingTop = startRow * lineHeightInPixels
paddingBottom = (editor.getScreenLineCount() - endRow) * lineHeightInPixels
div className: 'lines', ref: 'lines', [
div className: 'spacer', key: 'top-spacer', style: {height: precedingHeight}
(for tokenizedLine in @props.editor.linesForScreenRows(startRow, endRow - 1)
LineComponent({tokenizedLine, showIndentGuide, key: tokenizedLine.id}))...
div className: 'spacer', key: 'bottom-spacer', style: {height: followingHeight}
]
div className: 'lines', ref: 'lines', style: {paddingTop, paddingBottom},
for tokenizedLine in @props.editor.linesForScreenRows(startRow, endRow - 1)
LineComponent({tokenizedLine, showIndentGuide, key: tokenizedLine.id})
componentDidMount: ->
@measuredLines = new WeakSet
@@ -62,7 +59,7 @@ LinesComponent = React.createClass
for tokenizedLine, i in @props.editor.linesForScreenRows(visibleStartRow, visibleEndRow - 1)
unless @measuredLines.has(tokenizedLine)
lineNode = linesNode.children[i + 1]
lineNode = linesNode.children[i]
@measureCharactersInLine(tokenizedLine, lineNode)
measureCharactersInLine: (tokenizedLine, lineNode) ->