Paste selection clipboard after finalizing selections

This commit is contained in:
Kevin Sawicki
2014-12-18 09:26:14 -08:00
parent fa090345a8
commit d642553351

View File

@@ -404,7 +404,7 @@ TextEditorComponent = React.createClass
window.addEventListener 'resize', @requestHeightAndWidthMeasurement
@listenForIMEEvents()
@listenForMiddleMousePaste() if process.platform is 'linux'
@trackSelectionClipboard() if process.platform is 'linux'
listenForIMEEvents: ->
node = @getDOMNode()
@@ -432,15 +432,9 @@ TextEditorComponent = React.createClass
editor.insertText(selectedText, select: true, undo: 'skip')
event.target.value = ''
listenForMiddleMousePaste: ->
clipboard = require 'clipboard'
@refs.scrollView.getDOMNode().addEventListener 'mouseup', ({which}) =>
return unless which is 2
if selection = clipboard.readText('selection')
@props.editor.insertText(selection)
# Listen for selection changes and store the currently selected text
# in the selection clipboard. This is only applicable on Linux.
trackSelectionClipboard: ->
@subscribe @props.editor.onDidChangeSelectionRange =>
if selectedText = @props.editor.getSelectedText()
# This uses ipc.send instead of clipboard.writeText because
@@ -769,15 +763,21 @@ TextEditorComponent = React.createClass
# Stop dragging when cursor enters dev tools because we can't detect mouseup
onMouseUp() if event.which is 0
onMouseUp = ->
onMouseUp = (event) ->
stopDragging()
editor.finalizeSelections()
pasteSelectionClipboard(event)
stopDragging = ->
dragging = false
window.removeEventListener('mousemove', onMouseMove)
window.removeEventListener('mouseup', onMouseUp)
pasteSelectionClipboard = (event) ->
if event.which is 2 and process.platform is 'linux'
if selection = require('clipboard').readText('selection')
editor.insertText(selection)
window.addEventListener('mousemove', onMouseMove)
window.addEventListener('mouseup', onMouseUp)