Merge pull request #14063 from dietmar/linux_middle_mouse_8648

fixing middle mouse button clipboard paste on linux (atom:atom#8648)
This commit is contained in:
Bryant Ung 2017-04-04 14:22:40 -07:00 committed by GitHub
commit 8bc325b922
2 changed files with 40 additions and 9 deletions

View File

@ -5019,6 +5019,35 @@ describe('TextEditorComponent', function () {
expect(atom.clipboard.read()).toBe('sort')
expect(editor.lineTextForBufferRow(10)).toBe('sort')
})
it('pastes the previously selected text at the clicked location, left clicks do not interfere', async function () {
let clipboardWrittenTo = false
spyOn(require('electron').ipcRenderer, 'send').andCallFake(function (eventName, selectedText) {
if (eventName === 'write-text-to-selection-clipboard') {
require('../src/safe-clipboard').writeText(selectedText, 'selection')
clipboardWrittenTo = true
}
})
atom.clipboard.write('')
component.trackSelectionClipboard()
editor.setSelectedBufferRange([[1, 6], [1, 10]])
advanceClock(0)
componentNode.querySelector('.scroll-view').dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenPosition([10, 0]), {
button: 0
}))
componentNode.querySelector('.scroll-view').dispatchEvent(buildMouseEvent('mouseup', clientCoordinatesForScreenPosition([10, 0]), {
which: 1
}))
componentNode.querySelector('.scroll-view').dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenPosition([10, 0]), {
button: 1
}))
componentNode.querySelector('.scroll-view').dispatchEvent(buildMouseEvent('mouseup', clientCoordinatesForScreenPosition([10, 0]), {
which: 2
}))
expect(atom.clipboard.read()).toBe('sort')
expect(editor.lineTextForBufferRow(10)).toBe('sort')
})
})
function buildMouseEvent (type, ...propertiesObjects) {

View File

@ -525,9 +525,17 @@ class TextEditorComponent
@presenter.invalidateBlockDecorationDimensions(arguments...)
onMouseDown: (event) =>
unless event.button is 0 or (event.button is 1 and process.platform is 'linux')
# Only handle mouse down events for left mouse button on all platforms
# and middle mouse button on Linux since it pastes the selection clipboard
# Handle middle mouse button on linux platform only (paste clipboard)
if event.button is 1 and process.platform is 'linux'
if selection = require('./safe-clipboard').readText('selection')
screenPosition = @screenPositionForMouseEvent(event)
@editor.setCursorScreenPosition(screenPosition, autoscroll: false)
@editor.insertText(selection)
return
# Handle mouse down events for left mouse button only
# (except middle mouse button on linux platform, see above)
unless event.button is 0
return
return if event.target?.classList.contains('horizontal-scrollbar')
@ -674,7 +682,6 @@ class TextEditorComponent
stopDragging()
@editor.finalizeSelections()
@editor.mergeIntersectingSelections()
pasteSelectionClipboard(event)
stopDragging = ->
dragging = false
@ -714,11 +721,6 @@ class TextEditorComponent
scaleScrollDelta = (scrollDelta) ->
Math.pow(scrollDelta / 2, 3) / 280
pasteSelectionClipboard = (event) =>
if event?.which is 2 and process.platform is 'linux'
if selection = require('./safe-clipboard').readText('selection')
@editor.insertText(selection)
window.addEventListener('mousemove', onMouseMove)
window.addEventListener('mouseup', onMouseUp)
disposables = new CompositeDisposable