diff --git a/spec/text-editor-component-spec.coffee b/spec/text-editor-component-spec.coffee index 2144eb988..ac176c66d 100644 --- a/spec/text-editor-component-spec.coffee +++ b/spec/text-editor-component-spec.coffee @@ -1230,6 +1230,22 @@ describe "TextEditorComponent", -> beforeEach -> linesNode = componentNode.querySelector('.lines') + describe "when the mouse is single-clicked below the last line", -> + it "moves the cursor to the end of file buffer position", -> + editor.setText('foo') + editor.setCursorBufferPosition([0, 0]) + height = 4.5 * lineHeightInPixels + wrapperNode.style.height = height + 'px' + wrapperNode.style.width = 10 * charWidth + 'px' + component.measureHeightAndWidth() + nextAnimationFrame() + + coordinates = clientCoordinatesForScreenPosition([0, 2]) + coordinates.clientY = height * 2 + linesNode.dispatchEvent(buildMouseEvent('mousedown', coordinates)) + nextAnimationFrame() + expect(editor.getCursorScreenPosition()).toEqual [0, 3] + describe "when a non-folded line is single-clicked", -> describe "when no modifier keys are held down", -> it "moves the cursor to the nearest screen position", -> diff --git a/src/display-buffer.coffee b/src/display-buffer.coffee index d64af3270..aa9c22737 100644 --- a/src/display-buffer.coffee +++ b/src/display-buffer.coffee @@ -662,6 +662,7 @@ class DisplayBuffer extends Model targetLeft = pixelPosition.left defaultCharWidth = @defaultCharWidth row = Math.floor(targetTop / @getLineHeightInPixels()) + targetLeft = Infinity if row > @getLastRow() row = Math.min(row, @getLastRow()) row = Math.max(0, row)