Extract a LinesComponent

This commit is contained in:
Nathan Sobo
2014-04-14 13:48:54 -06:00
parent 5c2eb053d8
commit e952ab2e02
4 changed files with 142 additions and 162 deletions

View File

@@ -27,7 +27,9 @@ describe "EditorComponent", ->
{component} = wrapperView
component.setLineHeight(1.3)
component.setFontSize(20)
{lineHeightInPixels, charWidth} = component.measureLineDimensions()
lineHeightInPixels = editor.getLineHeight()
charWidth = editor.getDefaultCharWidth()
node = component.getDOMNode()
verticalScrollbarNode = node.querySelector('.vertical-scrollbar')
horizontalScrollbarNode = node.querySelector('.horizontal-scrollbar')
@@ -35,7 +37,7 @@ describe "EditorComponent", ->
describe "line rendering", ->
it "renders only the currently-visible lines", ->
node.style.height = 4.5 * lineHeightInPixels + 'px'
component.updateAllDimensions()
component.updateModelDimensions()
lines = node.querySelectorAll('.line')
expect(lines.length).toBe 6
@@ -111,7 +113,7 @@ describe "EditorComponent", ->
it "renders the currently-visible line numbers", ->
node.style.height = 4.5 * lineHeightInPixels + 'px'
component.updateAllDimensions()
component.updateModelDimensions()
lines = node.querySelectorAll('.line-number')
expect(lines.length).toBe 6
@@ -136,7 +138,7 @@ describe "EditorComponent", ->
editor.setSoftWrap(true)
node.style.height = 4.5 * lineHeightInPixels + 'px'
node.style.width = 30 * charWidth + 'px'
component.updateAllDimensions()
component.updateModelDimensions()
lines = node.querySelectorAll('.line-number')
expect(lines.length).toBe 6
@@ -153,7 +155,7 @@ describe "EditorComponent", ->
cursor1.setScreenPosition([0, 5])
node.style.height = 4.5 * lineHeightInPixels + 'px'
component.updateAllDimensions()
component.updateModelDimensions()
cursorNodes = node.querySelectorAll('.cursor')
expect(cursorNodes.length).toBe 1
@@ -248,7 +250,7 @@ describe "EditorComponent", ->
inputNode = node.querySelector('.hidden-input')
node.style.height = 5 * lineHeightInPixels + 'px'
node.style.width = 10 * charWidth + 'px'
component.updateAllDimensions()
component.updateModelDimensions()
expect(editor.getCursorScreenPosition()).toEqual [0, 0]
editor.setScrollTop(3 * lineHeightInPixels)
@@ -332,7 +334,7 @@ describe "EditorComponent", ->
it "moves the cursor to the nearest screen position", ->
node.style.height = 4.5 * lineHeightInPixels + 'px'
node.style.width = 10 * charWidth + 'px'
component.updateAllDimensions()
component.updateModelDimensions()
editor.setScrollTop(3.5 * lineHeightInPixels)
editor.setScrollLeft(2 * charWidth)
@@ -445,7 +447,7 @@ describe "EditorComponent", ->
describe "scrolling", ->
it "updates the vertical scrollbar when the scrollTop is changed in the model", ->
node.style.height = 4.5 * lineHeightInPixels + 'px'
component.updateAllDimensions()
component.updateModelDimensions()
expect(verticalScrollbarNode.scrollTop).toBe 0
@@ -454,7 +456,7 @@ describe "EditorComponent", ->
it "updates the horizontal scrollbar and scroll view content x transform based on the scrollLeft of the model", ->
node.style.width = 30 * charWidth + 'px'
component.updateAllDimensions()
component.updateModelDimensions()
scrollViewContentNode = node.querySelector('.scroll-view-content')
expect(scrollViewContentNode.style['-webkit-transform']).toBe "translate(0px, 0px)"
@@ -466,7 +468,7 @@ describe "EditorComponent", ->
it "updates the scrollLeft of the model when the scrollLeft of the horizontal scrollbar changes", ->
node.style.width = 30 * charWidth + 'px'
component.updateAllDimensions()
component.updateModelDimensions()
expect(editor.getScrollLeft()).toBe 0
horizontalScrollbarNode.scrollLeft = 100
@@ -478,7 +480,7 @@ describe "EditorComponent", ->
it "updates the horizontal or vertical scrollbar depending on which delta is greater (x or y)", ->
node.style.height = 4.5 * lineHeightInPixels + 'px'
node.style.width = 20 * charWidth + 'px'
component.updateAllDimensions()
component.updateModelDimensions()
expect(verticalScrollbarNode.scrollTop).toBe 0
expect(horizontalScrollbarNode.scrollLeft).toBe 0