From f5c8b04337f47c353f8b2277369797183d5fed06 Mon Sep 17 00:00:00 2001 From: Luke Pommersheim Date: Wed, 22 Jul 2015 11:16:27 +0200 Subject: [PATCH] Add function that only copies selected text unless the cursor is at the beginning of the line. --- src/text-editor-element.coffee | 1 + src/text-editor.coffee | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/text-editor-element.coffee b/src/text-editor-element.coffee index 85bcfd145..fc027b0d8 100644 --- a/src/text-editor-element.coffee +++ b/src/text-editor-element.coffee @@ -302,6 +302,7 @@ atom.commands.add 'atom-text-editor', stopEventPropagationAndGroupUndo( 'editor:transpose': -> @transpose() 'editor:upper-case': -> @upperCase() 'editor:lower-case': -> @lowerCase() + 'editor:copy-selection': -> @copyOnlySelectedText() ) atom.commands.add 'atom-text-editor:not([mini])', stopEventPropagation( diff --git a/src/text-editor.coffee b/src/text-editor.coffee index 8a4e40a11..220e99f2b 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -2587,6 +2587,18 @@ class TextEditor extends Model maintainClipboard = true return + + # Essential: For each selection, only copy hightlighted text. Line is coptied if no selected text and cursor is at the beginning of the line + copyOnlySelectedText: -> + maintainClipboard = false + for selection in @getSelectionsOrderedByBufferPosition() + if not selection.isEmpty() + selection.copy(maintainClipboard, true) + else if selection.isEmpty() and selection.cursor.isAtBeginningOfLine() + @copySelectedText() + maintainClipboard = true + return + # Essential: For each selection, cut the selected text. cutSelectedText: -> maintainClipboard = false