Account for padding-left on the scroll view when soft-wrapping lines

Fixes #2844
This commit is contained in:
Nathan Sobo
2014-07-07 14:02:24 -06:00
parent 2de42303d4
commit fad2a63a14
2 changed files with 16 additions and 2 deletions

View File

@@ -1814,9 +1814,11 @@ describe "EditorComponent", ->
wrapperView.show()
expect(node.querySelector('.cursor').style['-webkit-transform']).toBe "translate3d(#{9 * charWidth}px, 0px, 0px)"
describe "when the editor component is resized", ->
it "updates the component based on a new size", ->
describe "soft wrapping", ->
beforeEach ->
editor.setSoftWrap(true)
it "updates the wrap location when the editor is resized", ->
newHeight = 4 * editor.getLineHeightInPixels() + "px"
expect(newHeight).toBeLessThan node.style.height
node.style.height = newHeight
@@ -1831,6 +1833,16 @@ describe "EditorComponent", ->
runSetImmediateCallbacks()
expect(node.querySelector('.line').textContent).toBe "var quicksort "
it "accounts for the scroll view's padding when determining the wrap location", ->
scrollViewNode = node.querySelector('.scroll-view')
scrollViewNode.style.paddingLeft = 20 + 'px'
node.style.width = 30 * charWidth + 'px'
advanceClock(component.scrollViewMeasurementInterval)
runSetImmediateCallbacks()
expect(component.lineNodeForScreenRow(0).textContent).toBe "var quicksort = "
describe "default decorations", ->
it "applies .cursor-line decorations for line numbers overlapping selections", ->
editor.setCursorScreenPosition([4, 4])

View File

@@ -767,6 +767,8 @@ EditorComponent = React.createClass
if position is 'absolute' or width
clientWidth = scrollViewNode.clientWidth
paddingLeft = parseInt(getComputedStyle(scrollViewNode).paddingLeft)
clientWidth -= paddingLeft
editor.setWidth(clientWidth) if clientWidth > 0
measureLineHeightAndCharWidthsIfNeeded: (prevState) ->