Destroy only containing folds on selection

This commit is contained in:
Antonio Scandurra
2015-03-11 16:16:45 +01:00
parent b05a36d9f0
commit 2b98192276
3 changed files with 14 additions and 9 deletions

View File

@@ -1505,9 +1505,12 @@ describe "TextEditor", ->
editor.setSelectedScreenRanges([[[6, 2], [6, 4]]])
expect(editor.getSelectedScreenRanges()).toEqual [[[6, 2], [6, 4]]]
it "merges intersecting selections and unfolds the fold", ->
editor.setSelectedScreenRanges([[[2, 2], [3, 3]], [[3, 0], [5, 5]]])
expect(editor.getSelectedScreenRanges()).toEqual [[[2, 2], [8, 5]]]
it "merges intersecting selections and unfolds the fold which contain them", ->
editor.foldBufferRow(0)
# Use buffer ranges because only the first line is on screen
editor.setSelectedBufferRanges([[[2, 2], [3, 3]], [[3, 0], [5, 5]]])
expect(editor.getSelectedBufferRanges()).toEqual [[[2, 2], [5, 5]]]
it "recyles existing selection instances", ->
selection = editor.getLastSelection()

View File

@@ -100,7 +100,7 @@ class Selection extends Model
bufferRange = Range.fromObject(bufferRange)
@needsAutoscroll = options.autoscroll
options.reversed ?= @isReversed()
@editor.destroyFoldsIntersectingBufferRange(bufferRange) unless options.preserveFolds
@editor.destroyFoldsContainingBufferRange(bufferRange) unless options.preserveFolds
@modifySelection =>
needsFlash = options.flash
delete options.flash if options.flash?
@@ -251,8 +251,7 @@ class Selection extends Model
# Public: Selects all the text in the buffer.
selectAll: ->
@editor.unfoldAll()
@setBufferRange(@editor.buffer.getRange(), autoscroll: false, preserveFolds: true)
@setBufferRange(@editor.buffer.getRange(), autoscroll: false)
# Public: Selects all the text from the current cursor position to the
# beginning of the line.

View File

@@ -2241,7 +2241,7 @@ class TextEditor extends Model
# Returns the new {Selection}.
addSelection: (marker, options={}) ->
unless marker.getProperties().preserveFolds
@destroyFoldsIntersectingBufferRange(marker.getBufferRange())
@destroyFoldsContainingBufferRange(marker.getBufferRange())
cursor = @addCursor(marker)
selection = new Selection(_.extend({editor: this, marker, cursor}, options))
@selections.push(selection)
@@ -2776,12 +2776,15 @@ class TextEditor extends Model
# Remove any {Fold}s found that intersect the given buffer row.
destroyFoldsIntersectingBufferRange: (bufferRange) ->
@unfoldBufferRow(bufferRange.start.row)
@unfoldBufferRow(bufferRange.end.row)
@destroyFoldsContainingBufferRange(bufferRange)
for row in [bufferRange.end.row..bufferRange.start.row]
fold.destroy() for fold in @displayBuffer.foldsStartingAtBufferRow(row)
destroyFoldsContainingBufferRange: (bufferRange) ->
@unfoldBufferRow(bufferRange.start.row)
@unfoldBufferRow(bufferRange.end.row)
# {Delegates to: DisplayBuffer.largestFoldContainingBufferRow}
largestFoldContainingBufferRow: (bufferRow) ->
@displayBuffer.largestFoldContainingBufferRow(bufferRow)