Cut/copy whole lines when no text is selected

Closes #3643
This commit is contained in:
Max Brunsfeld 2014-11-11 09:44:08 -08:00
parent 43acb99f86
commit 7a87c22c7d
2 changed files with 30 additions and 0 deletions

View File

@ -2484,6 +2484,22 @@ describe "TextEditor", ->
expect(clipboard.readText()).toBe 'quicksort\nsort'
describe "when no text is selected", ->
beforeEach ->
editor.setSelectedBufferRanges([[1, 0], [1, 0]])
editor.addCursorAtBufferPosition([5, 0])
it "cuts the lines on which there are cursors", ->
editor.cutSelectedText()
expect(buffer.getLineCount()).toBe(11)
expect(buffer.lineForRow(1)).toBe(" if (items.length <= 1) return items;")
expect(buffer.lineForRow(4)).toBe(" current < pivot ? left.push(current) : right.push(current);")
expect(atom.clipboard.readWithMetadata().metadata.selections).toEqual([
"var quicksort = function () {\n"
" current = items.shift();\n"
])
describe ".cutToEndOfLine()", ->
describe "when soft wrap is on", ->
it "cuts up to the end of the line", ->
@ -2528,6 +2544,18 @@ describe "TextEditor", ->
'items'
])
describe "when no text is selected", ->
beforeEach ->
editor.setSelectedBufferRanges([[1, 0], [1, 0]])
editor.addCursorAtBufferPosition([5, 0])
it "copies the lines on which there are cursors", ->
editor.copySelectedText()
expect(atom.clipboard.readWithMetadata().metadata.selections).toEqual([
"var quicksort = function () {\n"
" current = items.shift();\n"
])
describe ".pasteText()", ->
it "pastes text into the buffer", ->
atom.clipboard.write('first')

View File

@ -2463,6 +2463,7 @@ class TextEditor extends Model
copySelectedText: ->
maintainClipboard = false
for selection in @getSelections()
selection.selectLine() if selection.isEmpty()
selection.copy(maintainClipboard)
maintainClipboard = true
@ -2470,6 +2471,7 @@ class TextEditor extends Model
cutSelectedText: ->
maintainClipboard = false
@mutateSelectedText (selection) ->
selection.selectLine() if selection.isEmpty()
selection.cut(maintainClipboard)
maintainClipboard = true