Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ export class TerminalLinkManager extends DisposableStore {
private _setupLinkDetector(id: string, detector: ITerminalLinkDetector, isExternal: boolean = false): ILinkProvider {
const detectorAdapter = this.add(this._instantiationService.createInstance(TerminalLinkDetectorAdapter, detector));
this.add(detectorAdapter.onDidActivateLink(e => {
// xterm.js activates links on mouseup of any button, only the primary button should
// activate. Bail before preventDefault as that would block the middle click paste of
// the selection clipboard on Linux.
if (e.event && e.event.button !== 0) {
return;
}
// Prevent default electron link handling so Alt+Click mode works normally
e.event?.preventDefault();
// Require correct modifier on click unless event is coming from linkQuickPick selection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { IDetectedLinks, TerminalLinkManager } from '../../browser/terminalLinkM
import { ITerminalCapabilityImplMap, ITerminalCapabilityStore, TerminalCapability } from '../../../../../../platform/terminal/common/capabilities/capabilities.js';
import { ITerminalConfiguration, ITerminalProcessManager } from '../../../../terminal/common/terminal.js';
import { TestViewDescriptorService } from '../../../../terminal/test/browser/xterm/xtermTerminal.test.js';
import { TestStorageService } from '../../../../../test/common/workbenchTestServices.js';
import { TestProductService, TestStorageService } from '../../../../../test/common/workbenchTestServices.js';
import type { ILink, Terminal } from '@xterm/xterm';
import { IXtermCore } from '../../../../terminal/browser/xterm-private.js';
import { TerminalLinkResolver } from '../../browser/terminalLinkResolver.js';
Expand All @@ -36,6 +36,7 @@ import { IHoverService } from '../../../../../../platform/hover/browser/hover.js
import { ILinkHoverTargetOptions } from '../../../../terminal/browser/widgets/terminalHoverWidget.js';
import { TerminalWidgetManager } from '../../../../terminal/browser/widgets/widgetManager.js';
import { TerminalLink } from '../../browser/terminalLink.js';
import { IProductService } from '../../../../../../platform/product/common/productService.js';

const defaultTerminalConfig: Partial<ITerminalConfiguration> = {
fontFamily: 'monospace',
Expand Down Expand Up @@ -64,6 +65,9 @@ class TestLinkManager extends TerminalLinkManager {
setLinks(links: IDetectedLinks): void {
this._links = links;
}
getDetectedLinks(y: number, type: 'word' | 'url' | 'localFile'): Promise<ILink[] | undefined> {
return super._getLinksForType(y, type);
}
}

suite('TerminalLinkManager', () => {
Expand Down Expand Up @@ -96,6 +100,7 @@ suite('TerminalLinkManager', () => {
instantiationService.stub(IStorageService, store.add(new TestStorageService()));
instantiationService.stub(IThemeService, themeService);
instantiationService.stub(IViewDescriptorService, viewDescriptorService);
instantiationService.stub(IProductService, TestProductService);

const TerminalCtor = (await importAMDNodeModule<typeof import('@xterm/xterm')>('@xterm/xterm', 'lib/xterm.js')).Terminal;
xterm = store.add(new TerminalCtor({ allowProposedApi: true, cols: 80, rows: 30, logger: TestXtermLogger }));
Expand Down Expand Up @@ -341,6 +346,18 @@ suite('TerminalLinkManager', () => {
strictEqual(fileLink, link2);
});
});

suite('link activation', () => {
test('should only prevent default for the primary button so middle click paste works', async () => {
await new Promise<void>(r => xterm.write('foo', r));
const [link] = (await linkManager.getDetectedLinks(1, 'word'))!;
const events = [0, 1, 2].map(button => new MouseEvent('mouseup', { button, cancelable: true }));
for (const e of events) {
link.activate(e, link.text);
}
deepStrictEqual(events.map(e => e.defaultPrevented), [true, false, false]);
});
});
});
function upcastPartial<T>(v: Partial<T>): T {
return v as T;
Expand Down
Loading