mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Duplicate multiple selections and multiple lines; folds are broken
This commit is contained in:
@@ -2669,6 +2669,30 @@ describe "Editor", ->
|
||||
expect(editor.lineForBufferRow(9)).toBe ' }; return sort(Array.apply(this, arguments)); };'
|
||||
expect(editor.getSelectedBufferRange()).toEqual [[9, 3], [9, 49]]
|
||||
|
||||
describe ".duplicateLines()", ->
|
||||
it "for each selection, duplicates all buffer lines intersected by the selection", ->
|
||||
editor.foldBufferRow(4)
|
||||
editor.setCursorBufferPosition([2, 5])
|
||||
editor.addSelectionForBufferRange([[3, 0], [8, 0]])
|
||||
|
||||
editor.duplicateLine()
|
||||
|
||||
expect(editor.getTextInBufferRange([[2, 0], [13, 5]])).toBe """
|
||||
\ if (items.length <= 1) return items;
|
||||
if (items.length <= 1) return items;
|
||||
var pivot = items.shift(), current, left = [], right = [];
|
||||
while(items.length > 0) {
|
||||
current = items.shift();
|
||||
current < pivot ? left.push(current) : right.push(current);
|
||||
}
|
||||
var pivot = items.shift(), current, left = [], right = [];
|
||||
while(items.length > 0) {
|
||||
current = items.shift();
|
||||
current < pivot ? left.push(current) : right.push(current);
|
||||
}
|
||||
"""
|
||||
expect(editor.getSelectedBufferRanges()).toEqual [[[3, 5], [3, 5]], [[9, 0], [14, 0]]]
|
||||
|
||||
describe ".shouldPromptToSave()", ->
|
||||
it "returns false when an edit session's buffer is in use by more than one session", ->
|
||||
jasmine.unspy(editor, 'shouldPromptToSave')
|
||||
|
||||
@@ -949,27 +949,16 @@ class Editor extends Model
|
||||
|
||||
# Duplicate the most recent cursor's current line.
|
||||
duplicateLine: ->
|
||||
return unless @getSelection().isEmpty()
|
||||
|
||||
@transact =>
|
||||
cursorPosition = @getCursorBufferPosition()
|
||||
cursorRowFolded = @isFoldedAtCursorRow()
|
||||
if cursorRowFolded
|
||||
screenRow = @screenPositionForBufferPosition(cursorPosition).row
|
||||
bufferRange = @bufferRangeForScreenRange([[screenRow], [screenRow + 1]])
|
||||
else
|
||||
bufferRange = new Range([cursorPosition.row], [cursorPosition.row + 1])
|
||||
for selection in @getSelectionsOrderedByBufferPosition().reverse()
|
||||
selectedBufferRange = selection.getBufferRange()
|
||||
[startRow, endRow] = selection.getBufferRowRange()
|
||||
endRow++
|
||||
rangeToDuplicate = [[startRow, 0], [endRow, 0]]
|
||||
textToDuplicate = @getTextInBufferRange(rangeToDuplicate)
|
||||
@buffer.insert([endRow, 0], textToDuplicate)
|
||||
|
||||
insertPosition = new Point(bufferRange.end.row)
|
||||
if insertPosition.row > @buffer.getLastRow()
|
||||
@unfoldCurrentRow() if cursorRowFolded
|
||||
@buffer.append("\n#{@getTextInBufferRange(bufferRange)}")
|
||||
@foldCurrentRow() if cursorRowFolded
|
||||
else
|
||||
@buffer.insert(insertPosition, @getTextInBufferRange(bufferRange))
|
||||
|
||||
@setCursorScreenPosition(@getCursorScreenPosition().translate([1]))
|
||||
@foldCurrentRow() if cursorRowFolded
|
||||
selection.setBufferRange(selectedBufferRange.translate([endRow - startRow, 0]))
|
||||
|
||||
mutateSelectedText: (fn) ->
|
||||
@transact => fn(selection) for selection in @getSelections()
|
||||
|
||||
Reference in New Issue
Block a user