Add function that only copies selected text unless the cursor is at the beginning of the line.

This commit is contained in:
Luke Pommersheim
2015-07-22 11:16:27 +02:00
parent 68135e68b8
commit f5c8b04337
2 changed files with 13 additions and 0 deletions

View File

@@ -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(

View File

@@ -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