Don't destroy folds that are completely contained within a selection

This commit is contained in:
Nathan Sobo
2017-10-25 12:15:33 -06:00
parent 622589f4f7
commit 00242541ae
4 changed files with 12 additions and 4 deletions

View File

@@ -70,7 +70,7 @@
"service-hub": "^0.7.4",
"sinon": "1.17.4",
"temp": "^0.8.3",
"text-buffer": "13.5.8",
"text-buffer": "13.6.0-0",
"typescript-simple": "1.0.0",
"underscore-plus": "^1.6.6",
"winreg": "^1.2.1",

View File

@@ -1871,7 +1871,7 @@ describe "TextEditor", ->
expect(selection1.getBufferRange()).toEqual [[2, 2], [3, 3]]
describe "when the 'preserveFolds' option is false (the default)", ->
it "removes folds that contain the selections", ->
it "removes folds that contain one or both of the selection's end points", ->
editor.setSelectedBufferRange([[0, 0], [0, 0]])
editor.foldBufferRowRange(1, 4)
editor.foldBufferRowRange(2, 3)
@@ -1884,6 +1884,9 @@ describe "TextEditor", ->
expect(editor.isFoldedAtScreenRow(6)).toBeFalsy()
expect(editor.isFoldedAtScreenRow(10)).toBeTruthy()
editor.setSelectedBufferRange([[10, 0], [12, 0]])
expect(editor.isFoldedAtScreenRow(10)).toBeTruthy()
describe "when the 'preserveFolds' option is true", ->
it "does not remove folds that contain the selections", ->
editor.setSelectedBufferRange([[0, 0], [0, 0]])

View File

@@ -87,7 +87,7 @@ class Selection extends Model
setBufferRange: (bufferRange, options={}) ->
bufferRange = Range.fromObject(bufferRange)
options.reversed ?= @isReversed()
@editor.destroyFoldsIntersectingBufferRange(bufferRange) unless options.preserveFolds
@editor.destroyFoldsContainingBufferPositions([bufferRange.start, bufferRange.end]) unless options.preserveFolds
@modifySelection =>
needsFlash = options.flash
delete options.flash if options.flash?

View File

@@ -2495,8 +2495,9 @@ class TextEditor extends Model
#
# Returns the added {Selection}.
addSelectionForBufferRange: (bufferRange, options={}) ->
bufferRange = Range.fromObject(bufferRange)
unless options.preserveFolds
@destroyFoldsIntersectingBufferRange(bufferRange)
@displayLayer.destroyFoldsContainingBufferPositions([bufferRange.start, bufferRange.end])
@selectionsMarkerLayer.markBufferRange(bufferRange, {invalidate: 'never', reversed: options.reversed ? false})
@getLastSelection().autoscroll() unless options.autoscroll is false
@getLastSelection()
@@ -3446,6 +3447,10 @@ class TextEditor extends Model
destroyFoldsIntersectingBufferRange: (bufferRange) ->
@displayLayer.destroyFoldsIntersectingBufferRange(bufferRange)
# Remove any {Fold}s found that intersect the given array of buffer positions.
destroyFoldsContainingBufferPositions: (bufferPositions) ->
@displayLayer.destroyFoldsContainingBufferPositions(bufferPositions)
###
Section: Gutters
###