mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Merge pull request #6239 from atom/as-fix-delete-line
Fix `deleteLine()` when multiple selections are on the same line
This commit is contained in:
@@ -3370,6 +3370,20 @@ describe "TextEditor", ->
|
||||
expect(buffer.lineForRow(0)).toBe(line2)
|
||||
expect(buffer.getLineCount()).toBe(count - 2)
|
||||
|
||||
it "deletes a line only once when multiple selections are on the same line", ->
|
||||
line1 = buffer.lineForRow(1)
|
||||
count = buffer.getLineCount()
|
||||
editor.setSelectedBufferRanges([
|
||||
[[0, 1], [0, 2]],
|
||||
[[0, 4], [0, 5]]
|
||||
])
|
||||
expect(buffer.lineForRow(0)).not.toBe(line1)
|
||||
|
||||
editor.deleteLine()
|
||||
|
||||
expect(buffer.lineForRow(0)).toBe(line1)
|
||||
expect(buffer.getLineCount()).toBe(count - 1)
|
||||
|
||||
it "only deletes first line if only newline is selected on second line", ->
|
||||
editor.setSelectedBufferRange([[0, 2], [1, 0]])
|
||||
line1 = buffer.lineForRow(1)
|
||||
|
||||
@@ -1026,6 +1026,7 @@ class TextEditor extends Model
|
||||
|
||||
# Extended: Delete all lines intersecting selections.
|
||||
deleteLine: ->
|
||||
@mergeSelectionsOnSameRows()
|
||||
@mutateSelectedText (selection) -> selection.deleteLine()
|
||||
|
||||
###
|
||||
@@ -2048,6 +2049,19 @@ class TextEditor extends Model
|
||||
# the function with merging suppressed, then merges intersecting selections
|
||||
# afterward.
|
||||
mergeIntersectingSelections: (args...) ->
|
||||
@mergeSelections args..., (previousSelection, currentSelection) ->
|
||||
exclusive = not currentSelection.isEmpty() and not previousSelection.isEmpty()
|
||||
|
||||
previousSelection.intersectsWith(currentSelection, exclusive)
|
||||
|
||||
mergeSelectionsOnSameRows: (args...) ->
|
||||
@mergeSelections args..., (previousSelection, currentSelection) ->
|
||||
screenRange = currentSelection.getScreenRange()
|
||||
|
||||
previousSelection.intersectsScreenRowRange(screenRange.start.row, screenRange.end.row)
|
||||
|
||||
mergeSelections: (args...) ->
|
||||
mergePredicate = args.pop()
|
||||
fn = args.pop() if _.isFunction(_.last(args))
|
||||
options = args.pop() ? {}
|
||||
|
||||
@@ -2060,10 +2074,7 @@ class TextEditor extends Model
|
||||
|
||||
reducer = (disjointSelections, selection) ->
|
||||
adjacentSelection = _.last(disjointSelections)
|
||||
exclusive = not selection.isEmpty() and not adjacentSelection.isEmpty()
|
||||
intersects = adjacentSelection.intersectsWith(selection, exclusive)
|
||||
|
||||
if intersects
|
||||
if mergePredicate(adjacentSelection, selection)
|
||||
adjacentSelection.merge(selection, options)
|
||||
disjointSelections
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user