Skip lines that are too-short when adding non-empty selection below

This commit is contained in:
Nathan Sobo 2013-04-05 11:18:50 -06:00
parent 40d7fcf32c
commit 131df22c11
3 changed files with 53 additions and 40 deletions

View File

@ -709,43 +709,52 @@ describe "EditSession", ->
expect(editSession.getSelectedBufferRange()).toEqual rangeBefore
describe ".addSelectionBelow()", ->
it "selects the same region of the line below current selections if possible", ->
editSession.setSelectedBufferRange([[3, 16], [3, 21]])
editSession.addSelectionForBufferRange([[3, 25], [3, 34]])
editSession.addSelectionBelow()
expect(editSession.getSelectedBufferRanges()).toEqual [
[[3, 16], [3, 21]]
[[3, 25], [3, 34]]
[[4, 16], [4, 21]]
[[4, 25], [4, 29]]
]
for cursor in editSession.getCursors()
expect(cursor.isVisible()).toBeFalsy()
describe "when the selection is non-empty", ->
it "selects the same region of the line below current selections if possible", ->
editSession.setSelectedBufferRange([[3, 16], [3, 21]])
editSession.addSelectionForBufferRange([[3, 25], [3, 34]])
editSession.addSelectionBelow()
expect(editSession.getSelectedBufferRanges()).toEqual [
[[3, 16], [3, 21]]
[[3, 25], [3, 34]]
[[4, 16], [4, 21]]
[[4, 25], [4, 29]]
]
for cursor in editSession.getCursors()
expect(cursor.isVisible()).toBeFalsy()
it "honors the original selection's range (goal range) when adding across shorter lines", ->
editSession.setSelectedBufferRange([[3, 22], [3, 38]])
editSession.addSelectionBelow()
editSession.addSelectionBelow()
editSession.addSelectionBelow()
expect(editSession.getSelectedBufferRanges()).toEqual [
[[3, 22], [3, 38]]
[[4, 22], [4, 29]]
[[5, 22], [5, 30]]
[[6, 22], [6, 38]]
]
it "skips lines that are too short to create a non-empty selection", ->
editSession.setSelectedBufferRange([[3, 31], [3, 38]])
editSession.addSelectionBelow()
expect(editSession.getSelectedBufferRanges()).toEqual [
[[3, 31], [3, 38]]
[[6, 31], [6, 38]]
]
it "clears selection goal ranges when the selection changes", ->
editSession.setSelectedBufferRange([[3, 22], [3, 38]])
editSession.addSelectionBelow()
editSession.selectLeft()
editSession.addSelectionBelow()
editSession.addSelectionBelow()
expect(editSession.getSelectedBufferRanges()).toEqual [
[[3, 22], [3, 37]]
[[4, 22], [4, 29]]
[[5, 22], [5, 29]]
[[6, 22], [6, 28]]
]
it "honors the original selection's range (goal range) when adding across shorter lines", ->
editSession.setSelectedBufferRange([[3, 22], [3, 38]])
editSession.addSelectionBelow()
editSession.addSelectionBelow()
editSession.addSelectionBelow()
expect(editSession.getSelectedBufferRanges()).toEqual [
[[3, 22], [3, 38]]
[[4, 22], [4, 29]]
[[5, 22], [5, 30]]
[[6, 22], [6, 38]]
]
it "clears selection goal ranges when the selection changes", ->
editSession.setSelectedBufferRange([[3, 22], [3, 38]])
editSession.addSelectionBelow()
editSession.selectLeft()
editSession.addSelectionBelow()
editSession.addSelectionBelow()
expect(editSession.getSelectedBufferRanges()).toEqual [
[[3, 22], [3, 37]]
[[4, 22], [4, 29]]
[[5, 22], [5, 29]]
[[6, 22], [6, 28]]
]
describe "when the cursor is moved while there is a selection", ->
makeSelection = -> selection.setBufferRange [[1, 2], [1, 5]]

View File

@ -125,8 +125,8 @@ class EditSession
getTabLength: -> @displayBuffer.getTabLength()
setTabLength: (tabLength) -> @displayBuffer.setTabLength(tabLength)
clipBufferPosition: (bufferPosition) ->
@buffer.clipPosition(bufferPosition)
clipBufferPosition: (bufferPosition) -> @buffer.clipPosition(bufferPosition)
clipBufferRange: (range) -> @buffer.clipRange(range)
indentationForBufferRow: (bufferRow) ->
@indentLevelForLine(@lineForBufferRow(bufferRow))

View File

@ -154,9 +154,13 @@ class Selection
addSelectionBelow: ->
range = (@goalBufferRange ? @getBufferRange()).copy()
range.start.row++
range.end.row++
@editSession.addSelectionForBufferRange(range, goalBufferRange: range, suppressMerge: true)
nextRow = range.end.row + 1
for row in [nextRow..@editSession.getLastBufferRow()]
range.start.row = row
range.end.row = row
unless @editSession.clipBufferRange(range).isEmpty()
@editSession.addSelectionForBufferRange(range, goalBufferRange: range, suppressMerge: true)
break
insertText: (text, options={}) ->
oldBufferRange = @getBufferRange()