@theia/terminal 1.45.0 → 1.46.0-next.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -30
- package/lib/browser/base/terminal-service.d.ts +34 -34
- package/lib/browser/base/terminal-service.js +7 -7
- package/lib/browser/base/terminal-widget.d.ts +192 -192
- package/lib/browser/base/terminal-widget.js +34 -34
- package/lib/browser/index.d.ts +1 -1
- package/lib/browser/index.js +28 -28
- package/lib/browser/search/terminal-search-container.d.ts +3 -3
- package/lib/browser/search/terminal-search-container.js +28 -28
- package/lib/browser/search/terminal-search-widget.d.ts +30 -30
- package/lib/browser/search/terminal-search-widget.js +147 -147
- package/lib/browser/shell-terminal-profile.d.ts +20 -20
- package/lib/browser/shell-terminal-profile.js +42 -42
- package/lib/browser/terminal-contribution.d.ts +3 -3
- package/lib/browser/terminal-contribution.js +20 -20
- package/lib/browser/terminal-copy-on-selection-handler.d.ts +10 -10
- package/lib/browser/terminal-copy-on-selection-handler.js +103 -103
- package/lib/browser/terminal-file-link-provider.d.ts +24 -24
- package/lib/browser/terminal-file-link-provider.js +200 -200
- package/lib/browser/terminal-frontend-contribution.d.ts +115 -115
- package/lib/browser/terminal-frontend-contribution.d.ts.map +1 -1
- package/lib/browser/terminal-frontend-contribution.js +1078 -1056
- package/lib/browser/terminal-frontend-contribution.js.map +1 -1
- package/lib/browser/terminal-frontend-module.d.ts +5 -5
- package/lib/browser/terminal-frontend-module.js +117 -117
- package/lib/browser/terminal-link-helpers.d.ts +27 -27
- package/lib/browser/terminal-link-helpers.js +155 -155
- package/lib/browser/terminal-link-provider.d.ts +51 -51
- package/lib/browser/terminal-link-provider.js +197 -197
- package/lib/browser/terminal-preferences.d.ts +61 -61
- package/lib/browser/terminal-preferences.d.ts.map +1 -1
- package/lib/browser/terminal-preferences.js +357 -356
- package/lib/browser/terminal-preferences.js.map +1 -1
- package/lib/browser/terminal-profile-service.d.ts +58 -58
- package/lib/browser/terminal-profile-service.js +158 -158
- package/lib/browser/terminal-quick-open-service.d.ts +36 -36
- package/lib/browser/terminal-quick-open-service.js +137 -137
- package/lib/browser/terminal-theme-service.d.ts +21 -21
- package/lib/browser/terminal-theme-service.d.ts.map +1 -1
- package/lib/browser/terminal-theme-service.js +222 -218
- package/lib/browser/terminal-theme-service.js.map +1 -1
- package/lib/browser/terminal-url-link-provider.d.ts +11 -11
- package/lib/browser/terminal-url-link-provider.js +76 -76
- package/lib/browser/terminal-widget-impl.d.ts +180 -187
- package/lib/browser/terminal-widget-impl.d.ts.map +1 -1
- package/lib/browser/terminal-widget-impl.js +857 -867
- package/lib/browser/terminal-widget-impl.js.map +1 -1
- package/lib/common/base-terminal-protocol.d.ts +55 -55
- package/lib/common/base-terminal-protocol.js +84 -84
- package/lib/common/shell-terminal-protocol.d.ts +66 -66
- package/lib/common/shell-terminal-protocol.js +35 -35
- package/lib/common/terminal-common-module.d.ts +7 -7
- package/lib/common/terminal-common-module.js +31 -31
- package/lib/common/terminal-protocol.d.ts +12 -12
- package/lib/common/terminal-protocol.js +21 -21
- package/lib/common/terminal-watcher.d.ts +13 -13
- package/lib/common/terminal-watcher.js +70 -70
- package/lib/node/base-terminal-server.d.ts +24 -24
- package/lib/node/base-terminal-server.js +168 -168
- package/lib/node/buffering-stream.d.ts +39 -39
- package/lib/node/buffering-stream.js +75 -75
- package/lib/node/buffering-stream.spec.d.ts +1 -1
- package/lib/node/buffering-stream.spec.js +43 -43
- package/lib/node/index.d.ts +1 -1
- package/lib/node/index.js +28 -28
- package/lib/node/shell-process.d.ts +27 -27
- package/lib/node/shell-process.js +107 -107
- package/lib/node/shell-process.js.map +1 -1
- package/lib/node/shell-terminal-server.d.ts +30 -30
- package/lib/node/shell-terminal-server.js +212 -212
- package/lib/node/shell-terminal-server.spec.d.ts +1 -1
- package/lib/node/shell-terminal-server.spec.js +35 -35
- package/lib/node/terminal-backend-contribution.d.ts +9 -9
- package/lib/node/terminal-backend-contribution.js +75 -75
- package/lib/node/terminal-backend-contribution.slow-spec.d.ts +1 -1
- package/lib/node/terminal-backend-contribution.slow-spec.js +54 -54
- package/lib/node/terminal-backend-module.d.ts +11 -11
- package/lib/node/terminal-backend-module.js +69 -69
- package/lib/node/terminal-server.d.ts +9 -9
- package/lib/node/terminal-server.js +64 -64
- package/lib/node/terminal-server.spec.d.ts +1 -1
- package/lib/node/terminal-server.spec.js +41 -41
- package/lib/node/test/terminal-test-container.d.ts +2 -2
- package/lib/node/test/terminal-test-container.js +40 -40
- package/lib/package.spec.js +25 -25
- package/package.json +12 -12
- package/src/browser/base/terminal-service.ts +60 -60
- package/src/browser/base/terminal-widget.ts +254 -254
- package/src/browser/index.ts +17 -17
- package/src/browser/search/terminal-search-container.ts +28 -28
- package/src/browser/search/terminal-search-widget.tsx +161 -161
- package/src/browser/shell-terminal-profile.ts +45 -45
- package/src/browser/style/terminal-search.css +99 -99
- package/src/browser/style/terminal.css +32 -32
- package/src/browser/terminal-contribution.ts +19 -19
- package/src/browser/terminal-copy-on-selection-handler.ts +92 -92
- package/src/browser/terminal-file-link-provider.ts +200 -200
- package/src/browser/terminal-frontend-contribution.ts +1120 -1098
- package/src/browser/terminal-frontend-module.ts +136 -136
- package/src/browser/terminal-link-helpers.ts +187 -187
- package/src/browser/terminal-link-provider.ts +203 -203
- package/src/browser/terminal-preferences.ts +428 -427
- package/src/browser/terminal-profile-service.ts +180 -180
- package/src/browser/terminal-quick-open-service.ts +132 -132
- package/src/browser/terminal-theme-service.ts +213 -209
- package/src/browser/terminal-url-link-provider.ts +66 -66
- package/src/browser/terminal-widget-impl.ts +939 -936
- package/src/common/base-terminal-protocol.ts +125 -125
- package/src/common/shell-terminal-protocol.ts +103 -103
- package/src/common/terminal-common-module.ts +30 -30
- package/src/common/terminal-protocol.ts +32 -32
- package/src/common/terminal-watcher.ts +69 -69
- package/src/node/base-terminal-server.ts +173 -173
- package/src/node/buffering-stream.spec.ts +46 -46
- package/src/node/buffering-stream.ts +95 -95
- package/src/node/index.ts +17 -17
- package/src/node/shell-process.ts +101 -101
- package/src/node/shell-terminal-server.spec.ts +40 -40
- package/src/node/shell-terminal-server.ts +221 -221
- package/src/node/terminal-backend-contribution.slow-spec.ts +63 -63
- package/src/node/terminal-backend-contribution.ts +60 -60
- package/src/node/terminal-backend-module.ts +82 -82
- package/src/node/terminal-server.spec.ts +47 -47
- package/src/node/terminal-server.ts +52 -52
- package/src/node/test/terminal-test-container.ts +39 -39
- package/src/package.spec.ts +28 -28
|
@@ -1,203 +1,203 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2022 STMicroelectronics and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { CancellationToken, ContributionProvider, DisposableCollection, disposableTimeout, isOSX } from '@theia/core';
|
|
18
|
-
import { PreferenceService } from '@theia/core/lib/browser';
|
|
19
|
-
import { inject, injectable, interfaces, named, postConstruct } from '@theia/core/shared/inversify';
|
|
20
|
-
import { IBufferRange, ILink, ILinkDecorations } from 'xterm';
|
|
21
|
-
import { TerminalWidget } from './base/terminal-widget';
|
|
22
|
-
import { TerminalContribution } from './terminal-contribution';
|
|
23
|
-
import { convertLinkRangeToBuffer, getLinkContext, LinkContext } from './terminal-link-helpers';
|
|
24
|
-
import { TerminalWidgetImpl } from './terminal-widget-impl';
|
|
25
|
-
|
|
26
|
-
export const TerminalLinkProvider = Symbol('TerminalLinkProvider');
|
|
27
|
-
export interface TerminalLinkProvider {
|
|
28
|
-
provideLinks(line: string, terminal: TerminalWidget, cancelationToken?: CancellationToken): Promise<TerminalLink[]>;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const TerminalLink = Symbol('TerminalLink');
|
|
32
|
-
export interface TerminalLink {
|
|
33
|
-
startIndex: number;
|
|
34
|
-
length: number;
|
|
35
|
-
tooltip?: string;
|
|
36
|
-
handle(): Promise<void>;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const XtermLink = Symbol('XtermLink');
|
|
40
|
-
export const XtermLinkFactory = Symbol('XtermLinkFactory');
|
|
41
|
-
export type XtermLinkFactory = (link: TerminalLink, terminal: TerminalWidgetImpl, context: LinkContext) => ILink;
|
|
42
|
-
|
|
43
|
-
export function createXtermLinkFactory(ctx: interfaces.Context): XtermLinkFactory {
|
|
44
|
-
return (link: TerminalLink, terminal: TerminalWidgetImpl, context: LinkContext): ILink => {
|
|
45
|
-
const container = ctx.container.createChild();
|
|
46
|
-
container.bind(TerminalLink).toConstantValue(link);
|
|
47
|
-
container.bind(TerminalWidgetImpl).toConstantValue(terminal);
|
|
48
|
-
container.bind(LinkContext).toConstantValue(context);
|
|
49
|
-
container.bind(XtermLinkAdapter).toSelf().inSingletonScope();
|
|
50
|
-
container.bind(XtermLink).toService(XtermLinkAdapter);
|
|
51
|
-
const provider = container.get<ILink>(XtermLink);
|
|
52
|
-
return provider;
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
@injectable()
|
|
57
|
-
export class TerminalLinkProviderContribution implements TerminalContribution {
|
|
58
|
-
|
|
59
|
-
@inject(ContributionProvider) @named(TerminalLinkProvider)
|
|
60
|
-
protected readonly terminalLinkContributionProvider: ContributionProvider<TerminalLinkProvider>;
|
|
61
|
-
|
|
62
|
-
@inject(XtermLinkFactory)
|
|
63
|
-
protected readonly xtermLinkFactory: XtermLinkFactory;
|
|
64
|
-
|
|
65
|
-
onCreate(terminalWidget: TerminalWidgetImpl): void {
|
|
66
|
-
terminalWidget.getTerminal().registerLinkProvider({
|
|
67
|
-
provideLinks: (line, provideLinks) => this.provideTerminalLinks(terminalWidget, line, provideLinks)
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
protected async provideTerminalLinks(terminal: TerminalWidgetImpl, line: number, provideLinks: (links?: ILink[]) => void): Promise<void> {
|
|
72
|
-
const context = getLinkContext(terminal.getTerminal(), line);
|
|
73
|
-
|
|
74
|
-
const linkProviderPromises: Promise<TerminalLink[]>[] = [];
|
|
75
|
-
for (const provider of this.terminalLinkContributionProvider.getContributions()) {
|
|
76
|
-
linkProviderPromises.push(provider.provideLinks(context.text, terminal));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const xtermLinks: ILink[] = [];
|
|
80
|
-
for (const providerResult of await Promise.allSettled(linkProviderPromises)) {
|
|
81
|
-
if (providerResult.status === 'fulfilled') {
|
|
82
|
-
const providedLinks = providerResult.value;
|
|
83
|
-
xtermLinks.push(...providedLinks.map(link => this.xtermLinkFactory(link, terminal, context)));
|
|
84
|
-
} else {
|
|
85
|
-
console.warn('Terminal link provider failed to provide links', providerResult.reason);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
provideLinks(xtermLinks);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const DELAY_PREFERENCE = 'workbench.hover.delay';
|
|
95
|
-
|
|
96
|
-
@injectable()
|
|
97
|
-
export class XtermLinkAdapter implements ILink {
|
|
98
|
-
|
|
99
|
-
text: string;
|
|
100
|
-
range: IBufferRange;
|
|
101
|
-
decorations: ILinkDecorations;
|
|
102
|
-
|
|
103
|
-
@inject(TerminalLink) protected link: TerminalLink;
|
|
104
|
-
@inject(TerminalWidgetImpl) protected terminalWidget: TerminalWidgetImpl;
|
|
105
|
-
@inject(LinkContext) protected context: LinkContext;
|
|
106
|
-
@inject(PreferenceService) protected readonly preferences: PreferenceService;
|
|
107
|
-
|
|
108
|
-
protected toDispose = new DisposableCollection();
|
|
109
|
-
|
|
110
|
-
protected mouseEnteredHover = false;
|
|
111
|
-
protected mouseLeftHover = false;
|
|
112
|
-
|
|
113
|
-
@postConstruct()
|
|
114
|
-
initializeLinkFields(): void {
|
|
115
|
-
const range = {
|
|
116
|
-
startColumn: this.link.startIndex + 1,
|
|
117
|
-
startLineNumber: 1,
|
|
118
|
-
endColumn: this.link.startIndex + this.link.length + 1,
|
|
119
|
-
endLineNumber: 1
|
|
120
|
-
};
|
|
121
|
-
const terminal = this.terminalWidget.getTerminal();
|
|
122
|
-
this.range = convertLinkRangeToBuffer(this.context.lines, terminal.cols, range, this.context.startLine);
|
|
123
|
-
this.text = this.context.text.substring(this.link.startIndex, this.link.startIndex + this.link.length) || '';
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
hover(event: MouseEvent, text: string): void {
|
|
127
|
-
this.scheduleHover(event);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
protected scheduleHover(event: MouseEvent): void {
|
|
131
|
-
this.cancelHover();
|
|
132
|
-
const delay: number = this.preferences.get(DELAY_PREFERENCE) ?? 500;
|
|
133
|
-
this.toDispose.push(disposableTimeout(() => this.showHover(event), delay));
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
protected showHover(event: MouseEvent): void {
|
|
137
|
-
this.toDispose.push(this.terminalWidget.onMouseEnterLinkHover(() => this.mouseEnteredHover = true));
|
|
138
|
-
this.toDispose.push(this.terminalWidget.onMouseLeaveLinkHover(mouseEvent => {
|
|
139
|
-
this.mouseLeftHover = true;
|
|
140
|
-
this.leave(mouseEvent);
|
|
141
|
-
}));
|
|
142
|
-
this.terminalWidget.showLinkHover(
|
|
143
|
-
() => this.executeLinkHandler(),
|
|
144
|
-
event.clientX,
|
|
145
|
-
event.clientY,
|
|
146
|
-
this.link.tooltip
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
leave(event: MouseEvent): void {
|
|
151
|
-
this.toDispose.push(disposableTimeout(() => {
|
|
152
|
-
if (!this.mouseEnteredHover || this.mouseLeftHover) {
|
|
153
|
-
this.cancelHover();
|
|
154
|
-
}
|
|
155
|
-
}, 50));
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
protected cancelHover(): void {
|
|
159
|
-
this.mouseEnteredHover = false;
|
|
160
|
-
this.mouseLeftHover = false;
|
|
161
|
-
this.toDispose.dispose();
|
|
162
|
-
this.terminalWidget.hideLinkHover();
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
activate(event: MouseEvent, text: string): void {
|
|
166
|
-
event.preventDefault();
|
|
167
|
-
if (this.isModifierKeyDown(event) || this.wasTouchEvent(event, this.terminalWidget.lastTouchEndEvent)) {
|
|
168
|
-
this.executeLinkHandler();
|
|
169
|
-
} else {
|
|
170
|
-
this.terminalWidget.getTerminal().focus();
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
protected executeLinkHandler(): void {
|
|
175
|
-
this.link.handle();
|
|
176
|
-
this.cancelHover();
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
protected isModifierKeyDown(event: MouseEvent | KeyboardEvent): boolean {
|
|
180
|
-
return isOSX ? event.metaKey : event.ctrlKey;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
protected wasTouchEvent(event: MouseEvent, lastTouchEnd?: TouchEvent): boolean {
|
|
184
|
-
if (!lastTouchEnd) {
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
if ((event.timeStamp - lastTouchEnd.timeStamp) > 400) {
|
|
188
|
-
// A 'touchend' event typically precedes a matching 'click' event by 50ms.
|
|
189
|
-
return false;
|
|
190
|
-
}
|
|
191
|
-
if (Math.abs(event.pageX - (lastTouchEnd as unknown as MouseEvent).pageX) > 5) {
|
|
192
|
-
// Matching 'touchend' and 'click' events typically have the same page coordinates,
|
|
193
|
-
// plus or minus 1 pixel.
|
|
194
|
-
return false;
|
|
195
|
-
}
|
|
196
|
-
if (Math.abs(event.pageY - (lastTouchEnd as unknown as MouseEvent).pageY) > 5) {
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
// We have a match! This link was tapped.
|
|
200
|
-
return true;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2022 STMicroelectronics and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { CancellationToken, ContributionProvider, DisposableCollection, disposableTimeout, isOSX } from '@theia/core';
|
|
18
|
+
import { PreferenceService } from '@theia/core/lib/browser';
|
|
19
|
+
import { inject, injectable, interfaces, named, postConstruct } from '@theia/core/shared/inversify';
|
|
20
|
+
import { IBufferRange, ILink, ILinkDecorations } from 'xterm';
|
|
21
|
+
import { TerminalWidget } from './base/terminal-widget';
|
|
22
|
+
import { TerminalContribution } from './terminal-contribution';
|
|
23
|
+
import { convertLinkRangeToBuffer, getLinkContext, LinkContext } from './terminal-link-helpers';
|
|
24
|
+
import { TerminalWidgetImpl } from './terminal-widget-impl';
|
|
25
|
+
|
|
26
|
+
export const TerminalLinkProvider = Symbol('TerminalLinkProvider');
|
|
27
|
+
export interface TerminalLinkProvider {
|
|
28
|
+
provideLinks(line: string, terminal: TerminalWidget, cancelationToken?: CancellationToken): Promise<TerminalLink[]>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const TerminalLink = Symbol('TerminalLink');
|
|
32
|
+
export interface TerminalLink {
|
|
33
|
+
startIndex: number;
|
|
34
|
+
length: number;
|
|
35
|
+
tooltip?: string;
|
|
36
|
+
handle(): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const XtermLink = Symbol('XtermLink');
|
|
40
|
+
export const XtermLinkFactory = Symbol('XtermLinkFactory');
|
|
41
|
+
export type XtermLinkFactory = (link: TerminalLink, terminal: TerminalWidgetImpl, context: LinkContext) => ILink;
|
|
42
|
+
|
|
43
|
+
export function createXtermLinkFactory(ctx: interfaces.Context): XtermLinkFactory {
|
|
44
|
+
return (link: TerminalLink, terminal: TerminalWidgetImpl, context: LinkContext): ILink => {
|
|
45
|
+
const container = ctx.container.createChild();
|
|
46
|
+
container.bind(TerminalLink).toConstantValue(link);
|
|
47
|
+
container.bind(TerminalWidgetImpl).toConstantValue(terminal);
|
|
48
|
+
container.bind(LinkContext).toConstantValue(context);
|
|
49
|
+
container.bind(XtermLinkAdapter).toSelf().inSingletonScope();
|
|
50
|
+
container.bind(XtermLink).toService(XtermLinkAdapter);
|
|
51
|
+
const provider = container.get<ILink>(XtermLink);
|
|
52
|
+
return provider;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@injectable()
|
|
57
|
+
export class TerminalLinkProviderContribution implements TerminalContribution {
|
|
58
|
+
|
|
59
|
+
@inject(ContributionProvider) @named(TerminalLinkProvider)
|
|
60
|
+
protected readonly terminalLinkContributionProvider: ContributionProvider<TerminalLinkProvider>;
|
|
61
|
+
|
|
62
|
+
@inject(XtermLinkFactory)
|
|
63
|
+
protected readonly xtermLinkFactory: XtermLinkFactory;
|
|
64
|
+
|
|
65
|
+
onCreate(terminalWidget: TerminalWidgetImpl): void {
|
|
66
|
+
terminalWidget.getTerminal().registerLinkProvider({
|
|
67
|
+
provideLinks: (line, provideLinks) => this.provideTerminalLinks(terminalWidget, line, provideLinks)
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
protected async provideTerminalLinks(terminal: TerminalWidgetImpl, line: number, provideLinks: (links?: ILink[]) => void): Promise<void> {
|
|
72
|
+
const context = getLinkContext(terminal.getTerminal(), line);
|
|
73
|
+
|
|
74
|
+
const linkProviderPromises: Promise<TerminalLink[]>[] = [];
|
|
75
|
+
for (const provider of this.terminalLinkContributionProvider.getContributions()) {
|
|
76
|
+
linkProviderPromises.push(provider.provideLinks(context.text, terminal));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const xtermLinks: ILink[] = [];
|
|
80
|
+
for (const providerResult of await Promise.allSettled(linkProviderPromises)) {
|
|
81
|
+
if (providerResult.status === 'fulfilled') {
|
|
82
|
+
const providedLinks = providerResult.value;
|
|
83
|
+
xtermLinks.push(...providedLinks.map(link => this.xtermLinkFactory(link, terminal, context)));
|
|
84
|
+
} else {
|
|
85
|
+
console.warn('Terminal link provider failed to provide links', providerResult.reason);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
provideLinks(xtermLinks);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const DELAY_PREFERENCE = 'workbench.hover.delay';
|
|
95
|
+
|
|
96
|
+
@injectable()
|
|
97
|
+
export class XtermLinkAdapter implements ILink {
|
|
98
|
+
|
|
99
|
+
text: string;
|
|
100
|
+
range: IBufferRange;
|
|
101
|
+
decorations: ILinkDecorations;
|
|
102
|
+
|
|
103
|
+
@inject(TerminalLink) protected link: TerminalLink;
|
|
104
|
+
@inject(TerminalWidgetImpl) protected terminalWidget: TerminalWidgetImpl;
|
|
105
|
+
@inject(LinkContext) protected context: LinkContext;
|
|
106
|
+
@inject(PreferenceService) protected readonly preferences: PreferenceService;
|
|
107
|
+
|
|
108
|
+
protected toDispose = new DisposableCollection();
|
|
109
|
+
|
|
110
|
+
protected mouseEnteredHover = false;
|
|
111
|
+
protected mouseLeftHover = false;
|
|
112
|
+
|
|
113
|
+
@postConstruct()
|
|
114
|
+
initializeLinkFields(): void {
|
|
115
|
+
const range = {
|
|
116
|
+
startColumn: this.link.startIndex + 1,
|
|
117
|
+
startLineNumber: 1,
|
|
118
|
+
endColumn: this.link.startIndex + this.link.length + 1,
|
|
119
|
+
endLineNumber: 1
|
|
120
|
+
};
|
|
121
|
+
const terminal = this.terminalWidget.getTerminal();
|
|
122
|
+
this.range = convertLinkRangeToBuffer(this.context.lines, terminal.cols, range, this.context.startLine);
|
|
123
|
+
this.text = this.context.text.substring(this.link.startIndex, this.link.startIndex + this.link.length) || '';
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
hover(event: MouseEvent, text: string): void {
|
|
127
|
+
this.scheduleHover(event);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
protected scheduleHover(event: MouseEvent): void {
|
|
131
|
+
this.cancelHover();
|
|
132
|
+
const delay: number = this.preferences.get(DELAY_PREFERENCE) ?? 500;
|
|
133
|
+
this.toDispose.push(disposableTimeout(() => this.showHover(event), delay));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
protected showHover(event: MouseEvent): void {
|
|
137
|
+
this.toDispose.push(this.terminalWidget.onMouseEnterLinkHover(() => this.mouseEnteredHover = true));
|
|
138
|
+
this.toDispose.push(this.terminalWidget.onMouseLeaveLinkHover(mouseEvent => {
|
|
139
|
+
this.mouseLeftHover = true;
|
|
140
|
+
this.leave(mouseEvent);
|
|
141
|
+
}));
|
|
142
|
+
this.terminalWidget.showLinkHover(
|
|
143
|
+
() => this.executeLinkHandler(),
|
|
144
|
+
event.clientX,
|
|
145
|
+
event.clientY,
|
|
146
|
+
this.link.tooltip
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
leave(event: MouseEvent): void {
|
|
151
|
+
this.toDispose.push(disposableTimeout(() => {
|
|
152
|
+
if (!this.mouseEnteredHover || this.mouseLeftHover) {
|
|
153
|
+
this.cancelHover();
|
|
154
|
+
}
|
|
155
|
+
}, 50));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
protected cancelHover(): void {
|
|
159
|
+
this.mouseEnteredHover = false;
|
|
160
|
+
this.mouseLeftHover = false;
|
|
161
|
+
this.toDispose.dispose();
|
|
162
|
+
this.terminalWidget.hideLinkHover();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
activate(event: MouseEvent, text: string): void {
|
|
166
|
+
event.preventDefault();
|
|
167
|
+
if (this.isModifierKeyDown(event) || this.wasTouchEvent(event, this.terminalWidget.lastTouchEndEvent)) {
|
|
168
|
+
this.executeLinkHandler();
|
|
169
|
+
} else {
|
|
170
|
+
this.terminalWidget.getTerminal().focus();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
protected executeLinkHandler(): void {
|
|
175
|
+
this.link.handle();
|
|
176
|
+
this.cancelHover();
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
protected isModifierKeyDown(event: MouseEvent | KeyboardEvent): boolean {
|
|
180
|
+
return isOSX ? event.metaKey : event.ctrlKey;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
protected wasTouchEvent(event: MouseEvent, lastTouchEnd?: TouchEvent): boolean {
|
|
184
|
+
if (!lastTouchEnd) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
if ((event.timeStamp - lastTouchEnd.timeStamp) > 400) {
|
|
188
|
+
// A 'touchend' event typically precedes a matching 'click' event by 50ms.
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
if (Math.abs(event.pageX - (lastTouchEnd as unknown as MouseEvent).pageX) > 5) {
|
|
192
|
+
// Matching 'touchend' and 'click' events typically have the same page coordinates,
|
|
193
|
+
// plus or minus 1 pixel.
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
if (Math.abs(event.pageY - (lastTouchEnd as unknown as MouseEvent).pageY) > 5) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
// We have a match! This link was tapped.
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
}
|