Cancel native middle-click paste on tab mouseup (#2518)
On Linux with primary-selection paste enabled, middle-clicking a tab to close it triggered an unwanted primary-selection paste into whichever terminal became active after the close. The existing onMouseDown preventDefault on each tab blocks Chromium's middle-button auto-scroll but does not block the native paste pipeline, which is gated on mouseup. After the tab unmounts via onAuxClick → onClose, focus moves to xterm's hidden textarea on the newly active terminal, and the primary selection lands there. Add a small named helper preventMiddleButtonDefault and wire it as onMouseUp on SortableTab, BrowserTab, and EditorFileTab. Mirrors the preventDefault that usePrimarySelectionPaste's enabled=false branch already performs for non-tab surfaces. No platform branching: the mouseup cancel is a no-op on macOS and Windows because there is no native primary-selection paste pipeline to cancel. Fixes #2346
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
||||
getDropIndicatorClasses,
|
||||
type DropIndicator
|
||||
} from './drop-indicator'
|
||||
import { preventMiddleButtonDefault } from './middle-button-default-guard'
|
||||
|
||||
function formatBrowserTabUrlLabel(url: string): string {
|
||||
if (url === ORCA_BROWSER_BLANK_URL || url === 'about:blank') {
|
||||
@@ -141,6 +142,7 @@ export default function BrowserTab({
|
||||
e.preventDefault()
|
||||
}
|
||||
}}
|
||||
onMouseUp={preventMiddleButtonDefault}
|
||||
onAuxClick={(e) => {
|
||||
if (e.button === 1) {
|
||||
e.preventDefault()
|
||||
|
||||
@@ -28,6 +28,7 @@ import { useAppStore } from '@/store'
|
||||
import { STATUS_COLORS, STATUS_LABELS } from '../right-sidebar/status-display'
|
||||
import type { GitFileStatus } from '../../../../shared/types'
|
||||
import type { OpenFile } from '../../store/slices/editor'
|
||||
import { preventMiddleButtonDefault } from './middle-button-default-guard'
|
||||
import { CLOSE_ALL_CONTEXT_MENUS_EVENT } from './SortableTab'
|
||||
import type { TabDragItemData } from '../tab-group/useTabDragSplit'
|
||||
import {
|
||||
@@ -231,6 +232,7 @@ export default function EditorFileTab({
|
||||
e.preventDefault()
|
||||
}
|
||||
}}
|
||||
onMouseUp={preventMiddleButtonDefault}
|
||||
onAuxClick={(e) => {
|
||||
if (e.button === 1) {
|
||||
e.preventDefault()
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
getDropIndicatorClasses,
|
||||
type DropIndicator
|
||||
} from './drop-indicator'
|
||||
import { preventMiddleButtonDefault } from './middle-button-default-guard'
|
||||
|
||||
type SortableTabProps = {
|
||||
tab: TerminalTab
|
||||
@@ -231,6 +232,7 @@ export default function SortableTab({
|
||||
e.preventDefault()
|
||||
}
|
||||
}}
|
||||
onMouseUp={preventMiddleButtonDefault}
|
||||
onAuxClick={(e) => {
|
||||
if (isEditing) {
|
||||
return
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import type { MouseEvent as ReactMouseEvent } from 'react'
|
||||
import { preventMiddleButtonDefault } from './middle-button-default-guard'
|
||||
|
||||
function buildEvent(button: number): ReactMouseEvent {
|
||||
return {
|
||||
button,
|
||||
preventDefault: vi.fn()
|
||||
} as unknown as ReactMouseEvent
|
||||
}
|
||||
|
||||
describe('preventMiddleButtonDefault', () => {
|
||||
it('cancels the default mouseup for middle-button (button === 1)', () => {
|
||||
const event = buildEvent(1)
|
||||
preventMiddleButtonDefault(event)
|
||||
expect(event.preventDefault).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('does not cancel the default mouseup for the left button (button === 0)', () => {
|
||||
const event = buildEvent(0)
|
||||
preventMiddleButtonDefault(event)
|
||||
expect(event.preventDefault).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not cancel the default mouseup for the right button (button === 2)', () => {
|
||||
const event = buildEvent(2)
|
||||
preventMiddleButtonDefault(event)
|
||||
expect(event.preventDefault).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,9 @@
|
||||
import type { MouseEvent as ReactMouseEvent } from 'react'
|
||||
|
||||
export function preventMiddleButtonDefault(event: ReactMouseEvent): void {
|
||||
if (event.button === 1) {
|
||||
// Why: Chromium's Linux primary-selection paste is gated on mouseup;
|
||||
// mousedown/auxclick cancellation alone still lets it reach the next terminal.
|
||||
event.preventDefault()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user