Add special paste behavior when copying/cutting w/ no selection

This commit is contained in:
Max Brunsfeld
2014-11-18 18:58:25 -08:00
parent 9a080bfd1b
commit 270642b2ea
3 changed files with 63 additions and 12 deletions

View File

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