From 932a6e64db6f6acc5d038581ab5a0af85b45889b Mon Sep 17 00:00:00 2001 From: Anton Kosyakov Date: Fri, 29 Nov 2019 15:30:20 +0000 Subject: [PATCH] [terminal] map to localhost links to proper external links To open localhost links remotely. Signed-off-by: Anton Kosyakov --- .../src/browser/terminal-linkmatcher.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/terminal/src/browser/terminal-linkmatcher.ts b/packages/terminal/src/browser/terminal-linkmatcher.ts index 13e0777b38619..e4b7a106e4714 100644 --- a/packages/terminal/src/browser/terminal-linkmatcher.ts +++ b/packages/terminal/src/browser/terminal-linkmatcher.ts @@ -16,9 +16,10 @@ import { injectable, inject } from 'inversify'; import { isOSX, } from '@theia/core'; -import { WindowService } from '@theia/core/lib/browser/window/window-service'; import { TerminalContribution } from './terminal-contribution'; import { TerminalWidgetImpl } from './terminal-widget-impl'; +import { open, OpenerService } from '@theia/core/lib/browser/opener-service'; +import URI from '@theia/core/lib/common/uri'; @injectable() export abstract class AbstractCmdClickTerminalContribution implements TerminalContribution { @@ -76,25 +77,24 @@ export abstract class AbstractCmdClickTerminalContribution implements TerminalCo @injectable() export class URLMatcher extends AbstractCmdClickTerminalContribution { - @inject(WindowService) - protected readonly windowService: WindowService; + @inject(OpenerService) + protected readonly openerService: OpenerService; async getRegExp(): Promise { return /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/; } getHandler(): (event: MouseEvent, uri: string) => void { - return (event: MouseEvent, uri: string) => { - this.windowService.openNewWindow(uri); - }; + return (event: MouseEvent, uri: string) => + open(this.openerService, new URI(uri)); } } @injectable() export class LocalhostMatcher extends AbstractCmdClickTerminalContribution { - @inject(WindowService) - protected readonly windowService: WindowService; + @inject(OpenerService) + protected readonly openerService: OpenerService; async getRegExp(): Promise { return /(https?:\/\/)?(localhost|127\.0\.0\.1|0\.0\.0\.0)(:[0-9]{1,5})?([-a-zA-Z0-9@:%_\+.~#?&//=]*)/; @@ -103,7 +103,7 @@ export class LocalhostMatcher extends AbstractCmdClickTerminalContribution { getHandler(): (event: MouseEvent, uri: string) => void { return (event: MouseEvent, matched: string) => { const uri = matched.startsWith('http') ? matched : `http://${matched}`; - this.windowService.openNewWindow(uri); + open(this.openerService, new URI(uri)); }; } }