Correctly position cursor on mousedown when editor is scrolled left

This commit is contained in:
Nathan Sobo 2014-04-10 12:28:58 -06:00
parent 95b24fb933
commit 96ebb9bf03
2 changed files with 4 additions and 2 deletions

View File

@ -325,8 +325,10 @@ describe "EditorComponent", ->
describe "when no modifier keys are held down", ->
it "moves the cursor to the nearest screen position", ->
node.style.height = 4.5 * lineHeightInPixels + 'px'
node.style.width = 10 * charWidth + 'px'
component.updateAllDimensions()
editor.setScrollTop(3.5 * lineHeightInPixels)
editor.setScrollLeft(2 * charWidth)
linesNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenPosition([4, 8])))
expect(editor.getCursorScreenPosition()).toEqual [4, 8]
@ -406,7 +408,7 @@ describe "EditorComponent", ->
clientCoordinatesForScreenPosition = (screenPosition) ->
positionOffset = editor.pixelPositionForScreenPosition(screenPosition)
scrollViewClientRect = node.querySelector('.scroll-view').getBoundingClientRect()
clientX = scrollViewClientRect.left + positionOffset.left
clientX = scrollViewClientRect.left + positionOffset.left - editor.getScrollLeft()
clientY = scrollViewClientRect.top + positionOffset.top - editor.getScrollTop()
{clientX, clientY}

View File

@ -436,7 +436,7 @@ EditorCompont = React.createClass
editorClientRect = @refs.scrollView.getDOMNode().getBoundingClientRect()
top = clientY - editorClientRect.top + editor.getScrollTop()
left = clientX - editorClientRect.left
left = clientX - editorClientRect.left + editor.getScrollLeft()
{top, left}
clearVisibleRowOverrides: ->