Merge pull request #3867 from atom/ks-select-past-last-line

Fix selecting past the last line
This commit is contained in:
Kevin Sawicki
2014-10-17 14:38:18 -07:00
2 changed files with 17 additions and 0 deletions

View File

@@ -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", ->

View File

@@ -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)