Skip to content

Commit 05e02c8

Browse files
committed
Ctrl+clicking a link in the OpenShift Terminal should open the URL #3543
Fixes: #3543 Signed-off-by: Victor Rubezhny <vrubezhny@redhat.com>
1 parent 7ed75f9 commit 05e02c8

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/webview/openshift-terminal/app/terminalInstance.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,21 @@ export const TerminalInstance = (props: {
159159
return new FitAddon();
160160
}, []);
161161

162+
// A workaround to https://github.com/microsoft/vscode/issues/186043
163+
function handleLink(event: MouseEvent, uri: string): void {
164+
window.vscodeApi.postMessage({
165+
kind: 'openExternal',
166+
data: {
167+
uuid: props.uuid,
168+
url: uri
169+
},
170+
});
171+
}
172+
162173
// The xtermjs instance
163174
const [term] = React.useState(() => {
164175
const newTerm = new Terminal();
165-
newTerm.loadAddon(new WebLinksAddon());
176+
newTerm.loadAddon(new WebLinksAddon(handleLink));
166177
newTerm.loadAddon(new WebglAddon());
167178
newTerm.loadAddon(fitAddon);
168179
newTerm.attachCustomKeyEventHandler((keyboardEvent: KeyboardEvent) => {

src/webview/openshift-terminal/openShiftTerminal.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import {
1414
WebviewView,
1515
WebviewViewProvider,
1616
WebviewViewResolveContext, window,
17-
workspace
17+
workspace,
18+
env
1819
} from 'vscode';
1920
import { SerializeAddon } from 'xterm-addon-serialize';
2021
import { Terminal } from 'xterm-headless';
@@ -412,7 +413,7 @@ export class OpenShiftTerminalManager implements WebviewViewProvider {
412413
// - `closeTerminal(uuid): void`: the given webview terminal was closed; kill the process if needed and dispose of all the resources for the terminal in node
413414
// - `termMuxUp(): void`: the webview has rendered for the first time and is ready to respond to `createTerminal` messages
414415
this.webview.onDidReceiveMessage(
415-
(event) => {
416+
async (event) => {
416417
const message = event as Message;
417418
const terminal = this.openShiftTerminals.get(message?.data?.uuid);
418419
if (terminal) {
@@ -442,6 +443,14 @@ export class OpenShiftTerminalManager implements WebviewViewProvider {
442443
} else if (message.kind === 'closeTerminal') {
443444
terminal.dispose();
444445
this.openShiftTerminals.delete(message?.data?.uuid);
446+
} else if (message.kind === 'openExternal') {
447+
if (message?.data?.url) {
448+
const result = await window.showInformationMessage(
449+
'Do you want to open the external website?', 'Yes', 'No');
450+
if (result === 'Yes') {
451+
void env.openExternal(message?.data?.url);
452+
}
453+
}
445454
}
446455
} else if (message.kind === 'termMuxUp') {
447456
// mark the webview as resolved, to signal to `createTerminal`

0 commit comments

Comments
 (0)