Fix regression: folds can be destroyed by clicking them

This commit is contained in:
Nathan Sobo
2013-05-06 08:27:43 -06:00
parent 3e937e9811
commit e8e0d5dd02
5 changed files with 15 additions and 3 deletions

View File

@@ -1943,9 +1943,11 @@ describe "Editor", ->
describe "when a fold placeholder line is clicked", ->
it "removes the associated fold and places the cursor at its beginning", ->
editor.setCursorBufferPosition([3,0])
editor.trigger 'editor:fold-current-row'
editSession.createFold(3, 5)
editor.find('.fold.line').mousedown()
foldLine = editor.find('.line.fold')
expect(foldLine).toExist()
foldLine.mousedown()
expect(editor.find('.fold')).not.toExist()
expect(editor.find('.fold-marker')).not.toExist()

View File

@@ -107,6 +107,10 @@ class DisplayBuffer
@buffer.markRange([[startRow, 0], [endRow, Infinity]], @foldMarkerAttributes())
@foldForMarker(foldMarker)
# Destroys the fold with the given id
destroyFoldWithId: (id) ->
@foldsByMarkerId[id]?.destroy()
# Removes any folds found that contain the given buffer row.
#
# bufferRow - The buffer row {Number} to check against

View File

@@ -540,6 +540,10 @@ class EditSession
createFold: (startRow, endRow) ->
@displayBuffer.createFold(startRow, endRow)
# {Delegates to: DisplayBuffer.destroyFoldWithId}
destroyFoldWithId: (id) ->
@displayBuffer.destroyFoldWithId(id)
# {Delegates to: DisplayBuffer.destroyFoldsContainingBufferRow}
destroyFoldsContainingBufferRow: (bufferRow) ->
@displayBuffer.destroyFoldsContainingBufferRow(bufferRow)

View File

@@ -621,7 +621,7 @@ class Editor extends View
false if @isFocused
@renderedLines.on 'mousedown', '.fold.line', (e) =>
@destroyFold($(e.currentTarget).attr('fold-id'))
@activeEditSession.destroyFoldWithId($(e.currentTarget).attr('fold-id'))
false
@renderedLines.on 'mousedown', (e) =>

View File

@@ -7,12 +7,14 @@ Point = require 'point'
# Their creation is managed by the {DisplayBuffer}.
module.exports =
class Fold
id: null
displayBuffer: null
marker: null
### Internal ###
constructor: (@displayBuffer, @marker) ->
@id = @marker.id
@displayBuffer.foldsByMarkerId[@marker.id] = this
@updateDisplayBuffer()
@marker.on 'destroyed', => @destroyed()