mirror of
https://github.com/atom/atom.git
synced 2026-02-13 08:04:56 -05:00
Add special paste behavior when copying/cutting w/ no selection
This commit is contained in:
@@ -2472,18 +2472,21 @@ class TextEditor extends Model
|
||||
if selection.isEmpty()
|
||||
previousRange = selection.getBufferRange()
|
||||
selection.selectLine()
|
||||
selection.copy(maintainClipboard)
|
||||
selection.copy(maintainClipboard, true)
|
||||
selection.setBufferRange(previousRange)
|
||||
else
|
||||
selection.copy(maintainClipboard)
|
||||
selection.copy(maintainClipboard, false)
|
||||
maintainClipboard = true
|
||||
|
||||
# Essential: For each selection, cut the selected text.
|
||||
cutSelectedText: ->
|
||||
maintainClipboard = false
|
||||
@mutateSelectedText (selection) ->
|
||||
selection.selectLine() if selection.isEmpty()
|
||||
selection.cut(maintainClipboard)
|
||||
if selection.isEmpty()
|
||||
selection.selectLine()
|
||||
selection.cut(maintainClipboard, true)
|
||||
else
|
||||
selection.cut(maintainClipboard, false)
|
||||
maintainClipboard = true
|
||||
|
||||
# Essential: For each selection, replace the selected text with the contents of
|
||||
@@ -2501,9 +2504,10 @@ class TextEditor extends Model
|
||||
|
||||
@mutateSelectedText (selection, index) =>
|
||||
if metadata.selections?.length is @getSelections().length
|
||||
{text, indentBasis} = metadata.selections[index]
|
||||
{text, indentBasis, fullLine} = metadata.selections[index]
|
||||
else
|
||||
[text, indentBasis] = [clipboardText, metadata.indentBasis]
|
||||
{indentBasis, fullLine} = metadata
|
||||
text = clipboardText
|
||||
|
||||
delete options.indentBasis
|
||||
{cursor} = selection
|
||||
@@ -2512,7 +2516,14 @@ class TextEditor extends Model
|
||||
if containsNewlines or !cursor.hasPrecedingCharactersOnLine()
|
||||
options.indentBasis ?= indentBasis
|
||||
|
||||
selection.insertText(text, options)
|
||||
if fullLine and selection.isEmpty()
|
||||
oldPosition = selection.getBufferRange().start
|
||||
selection.setBufferRange([[oldPosition.row, 0], [oldPosition.row, 0]])
|
||||
selection.insertText(text, options)
|
||||
newPosition = oldPosition.translate([1, 0])
|
||||
selection.setBufferRange([newPosition, newPosition])
|
||||
else
|
||||
selection.insertText(text, options)
|
||||
|
||||
# Public: For each selection, if the selection is empty, cut all characters
|
||||
# of the containing line following the cursor. Otherwise cut the selected
|
||||
|
||||
Reference in New Issue
Block a user