Merge pull request #4240 from atom/ks-write-text-async-to-selection-clipboard

Write text async to selection clipboard
This commit is contained in:
Kevin Sawicki 2014-11-19 11:52:46 -08:00
commit 9b28e7a47c
3 changed files with 14 additions and 1 deletions

View File

@ -2686,6 +2686,10 @@ describe "TextEditorComponent", ->
describe "middle mouse paste on Linux", ->
it "pastes the previously selected text", ->
spyOn(require('ipc'), 'send').andCallFake (eventName, selectedText) ->
if eventName is 'write-text-to-selection-clipboard'
require('clipboard').writeText(selectedText, 'selection')
atom.clipboard.write('')
component.listenForMiddleMousePaste()

View File

@ -238,6 +238,11 @@ class AtomApplication
win = BrowserWindow.fromWebContents(event.sender)
win[method](args...)
clipboard = null
ipc.on 'write-text-to-selection-clipboard', (event, selectedText) ->
clipboard ?= require 'clipboard'
clipboard.writeText(selectedText, 'selection')
# Public: Executes the given command.
#
# If it isn't handled globally, delegate to the currently focused window.

View File

@ -6,6 +6,7 @@ scrollbarStyle = require 'scrollbar-style'
{Range, Point} = require 'text-buffer'
grim = require 'grim'
{CompositeDisposable} = require 'event-kit'
ipc = require 'ipc'
GutterComponent = require './gutter-component'
InputComponent = require './input-component'
@ -444,7 +445,10 @@ TextEditorComponent = React.createClass
@subscribe @props.editor.onDidChangeSelectionRange =>
if selectedText = @props.editor.getSelectedText()
clipboard.writeText(selectedText, 'selection')
# This uses ipc.send instead of clipboard.writeText because
# clipboard.writeText is a sync ipc call on Linux and that
# will slow down selections.
ipc.send('write-text-to-selection-clipboard', selectedText)
observeConfig: ->
@subscribe atom.config.observe 'editor.useHardwareAcceleration', @setUseHardwareAcceleration