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