mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
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:
@@ -2412,10 +2412,13 @@ describe('TextEditorComponent', () => {
|
||||
ctrlKey: true
|
||||
})
|
||||
)
|
||||
expect(editor.getCursorScreenPositions()).toEqual([[1, 4]])
|
||||
expect(editor.getSelectedScreenRanges()).toEqual([
|
||||
[[1, 16], [1, 16]]
|
||||
])
|
||||
|
||||
// ctrl-click adds cursors on platforms *other* than macOS
|
||||
component.props.platform = 'win32'
|
||||
editor.setCursorScreenPosition([1, 4])
|
||||
component.didMouseDownOnContent(
|
||||
Object.assign(clientPositionForCharacter(component, 1, 16), {
|
||||
detail: 1,
|
||||
@@ -2675,42 +2678,18 @@ describe('TextEditorComponent', () => {
|
||||
expect(component.getScrollLeft()).toBe(maxScrollLeft)
|
||||
})
|
||||
|
||||
it('pastes the previously selected text when clicking the middle mouse button on Linux', async () => {
|
||||
spyOn(electron.ipcRenderer, 'send').andCallFake(function (eventName, selectedText) {
|
||||
if (eventName === 'write-text-to-selection-clipboard') {
|
||||
clipboard.writeText(selectedText, 'selection')
|
||||
}
|
||||
})
|
||||
|
||||
it('positions the cursor on clicking the middle mouse button on Linux', async () => {
|
||||
// The browser synthesizes the paste as a textInput event on mouseup
|
||||
// so it is not possible to test it here.
|
||||
const {component, editor} = buildComponent({platform: 'linux'})
|
||||
|
||||
// Middle mouse pasting.
|
||||
editor.setSelectedBufferRange([[1, 6], [1, 10]])
|
||||
await conditionPromise(() => TextEditor.clipboard.read() === 'sort')
|
||||
component.didMouseDownOnContent({
|
||||
button: 1,
|
||||
clientX: clientLeftForCharacter(component, 10, 0),
|
||||
clientY: clientTopForLine(component, 10)
|
||||
})
|
||||
expect(TextEditor.clipboard.read()).toBe('sort')
|
||||
expect(editor.lineTextForBufferRow(10)).toBe('sort')
|
||||
editor.undo()
|
||||
|
||||
// Ensure left clicks don't interfere.
|
||||
editor.setSelectedBufferRange([[1, 2], [1, 5]])
|
||||
await conditionPromise(() => TextEditor.clipboard.read() === 'var')
|
||||
component.didMouseDownOnContent({
|
||||
button: 0,
|
||||
detail: 1,
|
||||
clientX: clientLeftForCharacter(component, 10, 0),
|
||||
clientY: clientTopForLine(component, 10)
|
||||
})
|
||||
component.didMouseDownOnContent({
|
||||
button: 1,
|
||||
clientX: clientLeftForCharacter(component, 10, 0),
|
||||
clientY: clientTopForLine(component, 10)
|
||||
})
|
||||
expect(editor.lineTextForBufferRow(10)).toBe('var')
|
||||
expect(editor.getSelectedBufferRange()).toEqual([[10, 0], [10, 0]])
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user