mirror of
https://github.com/atom/atom.git
synced 2026-02-06 12:44:59 -05:00
If a selection ends on a fold, backspace/delete delete all lines inside the fold
This commit is contained in:
@@ -61,7 +61,7 @@ class DisplayBuffer
|
||||
[startRow, endRow] = @tokenizedBuffer.rowRangeForFoldAtBufferRow(currentRow) ? []
|
||||
continue unless startRow? and startRow <= bufferRow <= endRow
|
||||
|
||||
if fold = @largestFoldForBufferRow(startRow)
|
||||
if fold = @largestFoldStartingAtBufferRow(startRow)
|
||||
fold.destroy()
|
||||
else
|
||||
@createFold(startRow, endRow)
|
||||
@@ -121,7 +121,7 @@ class DisplayBuffer
|
||||
_.remove(folds, fold)
|
||||
delete @foldsById[fold.id]
|
||||
|
||||
largestFoldForBufferRow: (bufferRow) ->
|
||||
largestFoldStartingAtBufferRow: (bufferRow) ->
|
||||
return unless folds = @activeFolds[bufferRow]
|
||||
(folds.sort (a, b) -> b.endRow - a.endRow)[0]
|
||||
|
||||
@@ -200,7 +200,7 @@ class DisplayBuffer
|
||||
screenLine = @tokenizedBuffer.lineForScreenRow(currentBufferRow)
|
||||
screenLine.foldable = @tokenizedBuffer.isBufferRowFoldable(currentBufferRow)
|
||||
|
||||
if fold = @largestFoldForBufferRow(currentBufferRow)
|
||||
if fold = @largestFoldStartingAtBufferRow(currentBufferRow)
|
||||
screenLine = screenLine.copy()
|
||||
screenLine.fold = fold
|
||||
screenLine.bufferDelta = fold.getBufferDelta()
|
||||
|
||||
@@ -194,7 +194,7 @@ class EditSession
|
||||
@displayBuffer.destroyFoldsContainingBufferRow(bufferRow)
|
||||
|
||||
unfoldCurrentRow: (row) ->
|
||||
@displayBuffer.largestFoldForBufferRow(@getLastCursor().getCurrentBufferRow())?.destroy()
|
||||
@displayBuffer.largestFoldStartingAtBufferRow(@getLastCursor().getCurrentBufferRow())?.destroy()
|
||||
|
||||
destroyFold: (foldId) ->
|
||||
fold = @displayBuffer.foldsById[foldId]
|
||||
@@ -204,6 +204,9 @@ class EditSession
|
||||
isFoldedAtScreenRow: (screenRow) ->
|
||||
@lineForScreenRow(screenRow).fold?
|
||||
|
||||
largestFoldStartingAtBufferRow: (bufferRow) ->
|
||||
@displayBuffer.largestFoldStartingAtBufferRow(bufferRow)
|
||||
|
||||
autoIndentTextAfterBufferPosition: (text, bufferPosition) ->
|
||||
return { text } unless @autoIndent
|
||||
@tokenizedBuffer.autoIndentTextAfterBufferPosition(text, bufferPosition)
|
||||
|
||||
@@ -18,8 +18,13 @@ class Fold
|
||||
inspect: ->
|
||||
"Fold(#{@startRow}, #{@endRow})"
|
||||
|
||||
getBufferRange: ->
|
||||
new Range([@startRow, 0], [@endRow, Infinity])
|
||||
getBufferRange: ({includeNewline}={}) ->
|
||||
if includeNewline
|
||||
end = [@endRow + 1, 0]
|
||||
else
|
||||
end = [@endRow, Infinity]
|
||||
|
||||
new Range([@startRow, 0], end)
|
||||
|
||||
getBufferDelta: ->
|
||||
new Point(@endRow - @startRow + 1, 0)
|
||||
|
||||
@@ -132,9 +132,7 @@ class Selection
|
||||
@autoOutdent() if shouldOutdent
|
||||
|
||||
backspace: ->
|
||||
@editSession.destroyFoldsContainingBufferRow(@getBufferRange().end.row)
|
||||
|
||||
if @isEmpty()
|
||||
if @isEmpty() and not @editSession.isFoldedAtScreenRow(@cursor.getCurrentScreenRow())
|
||||
if @editSession.isFoldedAtScreenRow(@cursor.getCurrentScreenRow() - 1)
|
||||
@selectToBufferPosition([@cursor.getCurrentBufferRow() - 1, Infinity])
|
||||
else
|
||||
@@ -156,8 +154,13 @@ class Selection
|
||||
|
||||
deleteSelectedText: ->
|
||||
bufferRange = @getBufferRange()
|
||||
if fold = @editSession.largestFoldStartingAtBufferRow(bufferRange.end.row)
|
||||
bufferRange = bufferRange.union(fold.getBufferRange(includeNewline: true))
|
||||
|
||||
@editSession.buffer.delete(bufferRange) unless bufferRange.isEmpty()
|
||||
@clear() if @cursor
|
||||
if @cursor
|
||||
@cursor.setBufferPosition(bufferRange.start)
|
||||
@clear()
|
||||
|
||||
indentSelectedRows: ->
|
||||
range = @getBufferRange()
|
||||
|
||||
Reference in New Issue
Block a user