Skip to content

Commit

Permalink
If the cursor is at any buffer position inside a fold, backspace dele…
Browse files Browse the repository at this point in the history
…tes the folded text
  • Loading branch information
Nathan Sobo committed Jun 15, 2012
1 parent 8d516fe commit 95622dc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions spec/app/edit-session-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,8 @@ describe "EditSession", ->

describe "when the cursor is on a folded screen line", ->
it "deletes all of the folded lines along with the fold", ->
editSession.toggleFoldAtBufferRow(1)
editSession.setCursorScreenPosition([1, 0])
editSession.setCursorBufferPosition([3, 0])
editSession.toggleFold()
editSession.backspace()
expect(buffer.lineForRow(1)).toBe ""
expect(buffer.lineForRow(2)).toBe " return sort(Array.apply(this, arguments));"
Expand Down
7 changes: 7 additions & 0 deletions src/app/display-buffer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ class DisplayBuffer
largestFoldStartingAtScreenRow: (screenRow) ->
@largestFoldStartingAtBufferRow(@bufferRowForScreenRow(screenRow))

largestFoldContainingBufferRow: (bufferRow) ->
largestFold = null
for currentBufferRow in [bufferRow..0]
if fold = @largestFoldStartingAtBufferRow(currentBufferRow)
largestFold = fold if fold.endRow >= bufferRow
largestFold

screenLineRangeForBufferRange: (bufferRange) ->
@expandScreenRangeToLineEnds(
@lineMap.screenRangeForBufferRange(
Expand Down
3 changes: 3 additions & 0 deletions src/app/edit-session.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ class EditSession
largestFoldStartingAtBufferRow: (bufferRow) ->
@displayBuffer.largestFoldStartingAtBufferRow(bufferRow)

largestFoldContainingBufferRow: (bufferRow) ->
@displayBuffer.largestFoldContainingBufferRow(bufferRow)

largestFoldStartingAtScreenRow: (screenRow) ->
@displayBuffer.largestFoldStartingAtScreenRow(screenRow)

Expand Down
10 changes: 6 additions & 4 deletions src/app/selection.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,23 @@ class Selection
@deleteSelectedText()

delete: ->
deleteNewlinesAfterFolds = true
if @isEmpty()
if @cursor.isAtEndOfLine() and fold = @editSession.largestFoldStartingAtScreenRow(@cursor.getCurrentScreenRow() + 1)
@selectToBufferPosition(fold.getBufferRange().end)
deleteNewlinesAfterFolds = false
else
@selectRight()
@deleteSelectedText()
@deleteSelectedText({ deleteNewlinesAfterFolds })

deleteToEndOfWord: ->
@selectToEndOfWord() if @isEmpty()
@deleteSelectedText()

deleteSelectedText: ->
deleteSelectedText: (options = {}) ->
bufferRange = @getBufferRange()
if fold = @editSession.largestFoldStartingAtBufferRow(bufferRange.end.row)
bufferRange = bufferRange.union(fold.getBufferRange(includeNewline: true))
if fold = @editSession.largestFoldContainingBufferRow(bufferRange.end.row)
bufferRange = bufferRange.union(fold.getBufferRange(includeNewline: options.deleteNewlinesAfterFolds ? true))

@editSession.buffer.delete(bufferRange) unless bufferRange.isEmpty()
if @cursor
Expand Down

0 comments on commit 95622dc

Please sign in to comment.