From 7a87c22c7de28d119e5797ee079f45ba07837a05 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 11 Nov 2014 09:44:08 -0800 Subject: [PATCH] Cut/copy whole lines when no text is selected Closes #3643 --- spec/text-editor-spec.coffee | 28 ++++++++++++++++++++++++++++ src/text-editor.coffee | 2 ++ 2 files changed, 30 insertions(+) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index 58cc59374..7da0cb725 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -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') diff --git a/src/text-editor.coffee b/src/text-editor.coffee index f663f0a76..b9ce6f16e 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -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