Fix middle-mouse-button paste on Linux

Chrome now synthesizes a textInput event on mouseup for middle mouse
button clicks, which rendered our custom JS for handling that case
redundant.
This commit is contained in:
Nathan Sobo
2017-07-10 15:53:23 -06:00
parent cd27b49dc4
commit f6d2f966bf
2 changed files with 21 additions and 41 deletions

View File

@@ -1647,9 +1647,21 @@ class TextEditorComponent {
const {target, button, detail, ctrlKey, shiftKey, metaKey} = event
const platform = this.getPlatform()
// On Linux, position the cursor on middle mouse button click. A
// textInput event with the contents of the selection clipboard will be
// dispatched by the browser automatically on mouseup.
if (platform === 'linux' && button === 1) {
const screenPosition = this.screenPositionForMouseEvent(event)
model.setCursorScreenPosition(screenPosition, {autoscroll: false})
return
}
// Only handle mousedown events for left mouse button (or the middle mouse
// button on Linux where it pastes the selection clipboard).
if (!(button === 0 || (platform === 'linux' && button === 1))) return
if (button !== 0) return
// Ctrl-click brings up the context menu on macOS
if (platform === 'darwin' && ctrlKey) return
const screenPosition = this.screenPositionForMouseEvent(event)
@@ -1659,17 +1671,6 @@ class TextEditorComponent {
return
}
// Handle middle mouse button only on Linux (paste clipboard)
if (platform === 'linux' && button === 1) {
const selection = clipboard.readText('selection')
model.setCursorScreenPosition(screenPosition, {autoscroll: false})
model.insertText(selection)
return
}
// Ctrl-click brings up the context menu on macOS
if (platform === 'darwin' && ctrlKey) return
const addOrRemoveSelection = metaKey || (ctrlKey && platform !== 'darwin')
switch (detail) {