SelectLine : When multiple line selected, complete both first and last line.

This commit is contained in:
jc roy
2015-09-02 20:03:18 -04:00
parent 3351b01df9
commit 361ef308e2
2 changed files with 19 additions and 3 deletions

View File

@@ -1299,6 +1299,13 @@ describe "TextEditor", ->
editor.selectLinesContainingCursors()
expect(editor.getSelectedBufferRange()).toEqual [[0, 0], [2, 0]]
describe "when selection span multiple row", ->
it "complete selection to contain the entire first and last line", ->
selection = editor.getLastSelection()
selection.setBufferRange [[1, 10], [3, 20]]
editor.selectLinesContainingCursors()
expect(editor.getSelectedBufferRange()).toEqual [[1, 0], [4, 0]]
it "autoscrolls to the selection", ->
editor.setLineHeightInPixels(10)
editor.setDefaultCharWidth(10)

View File

@@ -324,9 +324,18 @@ class Selection extends Model
#
# * `row` The line {Number} to select (default: the row of the cursor).
selectLine: (row, options) ->
row ?= @cursor.getBufferPosition().row
range = @editor.bufferRangeForBufferRow(row, includeNewline: true)
@setBufferRange(@getBufferRange().union(range), options)
if row?
range = @editor.bufferRangeForBufferRow(row, includeNewline: true)
@setBufferRange(@getBufferRange().union(range), options)
else
rowStart = @marker.getStartBufferPosition().row
rangeStart = @editor.bufferRangeForBufferRow(rowStart, includeNewline: true)
rowEnd = @marker.getEndBufferPosition().row
rangeEnd = @editor.bufferRangeForBufferRow(rowEnd, includeNewline: true)
@setBufferRange(@getBufferRange().union(rangeStart).union(rangeEnd), options)
@linewise = true
@wordwise = false
@initialScreenRange = @getScreenRange()