Implements multiple selections clipboard paste

Includes:

  - Passing the selection index in the `Editor::mutateSelectedText`
method callback
  - Storing all the selections content on many calls of
`Selection::copy` with `maintainClipboard = true` in a metadata
`selections` array
  - Handling clipboard with a `selections` metadata in
the`Editor::pasteText` method
This commit is contained in:
abe33
2014-05-06 23:19:39 +02:00
parent e9ed45671f
commit fbabc6f455
2 changed files with 27 additions and 3 deletions

View File

@@ -503,11 +503,24 @@ class Selection extends Model
@delete()
# Public: Copies the current selection to the clipboard.
#
# If the `maintainClipboard` is set to `true`, a specific metadata property
# is created to store each content copied to the clipboard. The clipboard
# `text` still contains the concatenation of the clipboard with the
# current selection.
copy: (maintainClipboard=false) ->
return if @isEmpty()
text = @editor.buffer.getTextInRange(@getBufferRange())
if maintainClipboard
text = "#{atom.clipboard.read()}\n#{text}"
{text: clipboardText, metadata: clipboardMetadata} = atom.clipboard.readWithMetadata()
if clipboardMetadata? and clipboardMetadata.selections?
metadata = clipboardMetadata
clipboardMetadata.selections.push(text)
else
metadata = { selections: [clipboardText, text] }
text = "" + (clipboardText) + "\n" + text
else
metadata = { indentBasis: @editor.indentationForBufferRow(@getBufferRange().start.row) }