Bugfix: When the command panel makes a selection, it destroys surrounding folds

This commit is contained in:
Nathan Sobo
2012-07-26 10:09:28 -06:00
parent f2fa9793b1
commit 54616aee78
3 changed files with 20 additions and 4 deletions

View File

@@ -149,6 +149,18 @@ describe "CommandInterpreter", ->
runs ->
expect(editSession.getSelection().getBufferRange()).toEqual [[3,8], [3,13]]
it "removes folds that contain the selections", ->
waitsForPromise ->
editSession.createFold(5, 6)
editSession.createFold(10, 11)
editSession.setSelectedBufferRange([[4,16], [4,20]])
interpreter.eval('/pivot/', editSession)
runs ->
expect(editSession.getSelection().getBufferRange()).toEqual [[6,16], [6,21]]
expect(editSession.lineForScreenRow(5).fold).toBeUndefined()
expect(editSession.lineForScreenRow(10).fold).toBeDefined()
describe "address range", ->
describe "when two addresses are specified", ->
it "selects from the begining of the left address to the end of the right address", ->

View File

@@ -214,6 +214,10 @@ class EditSession
destroyFoldsContainingBufferRow: (bufferRow) ->
@displayBuffer.destroyFoldsContainingBufferRow(bufferRow)
destroyFoldsIntersectingBufferRange: (bufferRange) ->
for row in [bufferRange.start.row..bufferRange.end.row]
@destroyFoldsContainingBufferRow(row)
unfoldCurrentRow: ->
@largestFoldStartingAtBufferRow(@getLastCursor().getBufferRow())?.destroy()
@@ -322,7 +326,9 @@ class EditSession
@trigger 'add-selection', selection
selection
addSelectionForBufferRange: (bufferRange, options) ->
addSelectionForBufferRange: (bufferRange, options={}) ->
bufferRange = Range.fromObject(bufferRange)
@destroyFoldsIntersectingBufferRange(bufferRange) unless options.preserveFolds
@addCursor().selection.setBufferRange(bufferRange, options)
@mergeIntersectingSelections()
@@ -337,9 +343,6 @@ class EditSession
for bufferRange, i in bufferRanges
bufferRange = Range.fromObject(bufferRange)
unless options.preserveFolds
for row in [bufferRange.start.row..bufferRange.end.row]
@destroyFoldsContainingBufferRow(row)
if selections[i]
selections[i].setBufferRange(bufferRange, options)
else

View File

@@ -54,6 +54,7 @@ class Selection
[start, end] = [end, start] if options.reverse
@modifyScreenRange =>
@editSession.destroyFoldsIntersectingBufferRange(bufferRange) unless options.preserveFolds
@placeAnchor() unless @anchor
@modifySelection =>
@anchor.setBufferPosition(start, options)