mirror of
https://github.com/Eugeny/tabby.git
synced 2025-07-20 02:18:01 +00:00
updated xterm to v5 - fixes #5612
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
"author": "Eugene Pankov",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"untildify": "^4.0.0"
|
||||
"untildify": "^4.0.0",
|
||||
"xterm-addon-web-links": "^0.7.0"
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { Inject, Injectable } from '@angular/core'
|
||||
import { ConfigService, PlatformService, TranslateService } from 'tabby-core'
|
||||
import { TerminalDecorator, BaseTerminalTabComponent } from 'tabby-terminal'
|
||||
|
||||
import { ConfigService, PlatformService } from 'tabby-core'
|
||||
import { TerminalDecorator, BaseTerminalTabComponent, XTermFrontend } from 'tabby-terminal'
|
||||
import { WebLinksAddon } from 'xterm-addon-web-links'
|
||||
import { LinkHandler } from './api'
|
||||
|
||||
@Injectable()
|
||||
@@ -9,55 +9,47 @@ export class LinkHighlighterDecorator extends TerminalDecorator {
|
||||
constructor (
|
||||
private config: ConfigService,
|
||||
private platform: PlatformService,
|
||||
private translate: TranslateService,
|
||||
@Inject(LinkHandler) private handlers: LinkHandler[],
|
||||
) {
|
||||
super()
|
||||
}
|
||||
|
||||
attach (tab: BaseTerminalTabComponent): void {
|
||||
if (!(tab.frontend as any).xterm) {
|
||||
// not hterm
|
||||
if (!(tab.frontend instanceof XTermFrontend)) {
|
||||
// not xterm
|
||||
return
|
||||
}
|
||||
|
||||
tab.frontend.xterm.options.linkHandler = {
|
||||
activate: (event, uri) => {
|
||||
if (!this.willHandleEvent(event)) {
|
||||
return
|
||||
}
|
||||
this.platform.openExternal(uri)
|
||||
},
|
||||
}
|
||||
|
||||
for (const handler of this.handlers) {
|
||||
const getLink = async uri => handler.convert(uri, tab)
|
||||
const openLink = async uri => handler.handle(await getLink(uri), tab)
|
||||
|
||||
;(tab.frontend as any).xterm.registerLinkMatcher(
|
||||
handler.regex,
|
||||
(event: MouseEvent, uri: string) => {
|
||||
const addon = new WebLinksAddon(
|
||||
this.onClick.bind(this),
|
||||
async (event, uri) => {
|
||||
if (!this.willHandleEvent(event)) {
|
||||
return
|
||||
}
|
||||
if (!await handler.verify(await handler.convert(uri, tab), tab)) {
|
||||
return
|
||||
}
|
||||
openLink(uri)
|
||||
},
|
||||
{
|
||||
priority: handler.priority,
|
||||
validationCallback: async (uri: string, callback: (isValid: boolean) => void) => {
|
||||
callback(await handler.verify(await handler.convert(uri, tab), tab))
|
||||
},
|
||||
willLinkActivate: (event: MouseEvent, uri: string) => {
|
||||
if (event.button === 2) {
|
||||
this.platform.popupContextMenu([
|
||||
{
|
||||
click: () => openLink(uri),
|
||||
label: this.translate.instant('Open'),
|
||||
},
|
||||
{
|
||||
click: async () => {
|
||||
this.platform.setClipboard({ text: await getLink(uri) })
|
||||
},
|
||||
label: this.translate.instant('Copy'),
|
||||
},
|
||||
])
|
||||
return false
|
||||
}
|
||||
return this.willHandleEvent(event)
|
||||
},
|
||||
}
|
||||
urlRegex: handler.regex,
|
||||
},
|
||||
)
|
||||
|
||||
tab.frontend.xterm.loadAddon(addon)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -6,3 +6,8 @@ untildify@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/untildify/-/untildify-4.0.0.tgz#2bc947b953652487e4600949fb091e3ae8cd919b"
|
||||
integrity sha512-KK8xQ1mkzZeg9inewmFVDNkg3l5LUhoq9kN6iWYB/CC9YMG8HA+c1Q8HwDe6dEX7kErrEVNVBO3fWsVq5iDgtw==
|
||||
|
||||
xterm-addon-web-links@^0.7.0:
|
||||
version "0.7.0"
|
||||
resolved "https://registry.yarnpkg.com/xterm-addon-web-links/-/xterm-addon-web-links-0.7.0.tgz#dceac36170605f9db10a01d716bd83ee38f65c17"
|
||||
integrity sha512-6PqoqzzPwaeSq22skzbvyboDvSnYk5teUYEoKBwMYvhbkwOQkemZccjWHT5FnNA8o1aInTc4PRYAl4jjPucCKA==
|
||||
|
Reference in New Issue
Block a user