From 96ebb9bf0320ca9e378f8739709f500bc956c765 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 10 Apr 2014 12:28:58 -0600 Subject: [PATCH] Correctly position cursor on mousedown when editor is scrolled left --- spec/editor-component-spec.coffee | 4 +++- src/editor-component.coffee | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/editor-component-spec.coffee b/spec/editor-component-spec.coffee index bfb0b9b46..63851e786 100644 --- a/spec/editor-component-spec.coffee +++ b/spec/editor-component-spec.coffee @@ -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} diff --git a/src/editor-component.coffee b/src/editor-component.coffee index c8ffeb796..08ea30222 100644 --- a/src/editor-component.coffee +++ b/src/editor-component.coffee @@ -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: ->