fix: make local file links clickable (#11666)

Co-authored-by: MrXnneHang <xnnehang@gmail.com>
Co-authored-by: Eugene <inbox@null.page>
This commit is contained in:
Korewaxnne
2026-09-11 23:52:46 +02:00
committed by GitHub
co-authored by MrXnneHang Eugene
parent 9d50636d6c
commit 1d2a0c1b2a
2 changed files with 22 additions and 2 deletions
+21 -1
View File
@@ -4,6 +4,14 @@ import { TerminalDecorator, BaseTerminalTabComponent, XTermFrontend } from 'tabb
import { WebLinksAddon } from '@xterm/addon-web-links'
import { LinkHandler } from './api'
function parseURL (uri: string): URL|null {
try {
return new URL(uri)
} catch {
return null
}
}
@Injectable()
export class LinkHighlighterDecorator extends TerminalDecorator {
constructor (
@@ -21,11 +29,22 @@ export class LinkHighlighterDecorator extends TerminalDecorator {
}
tab.frontend.xterm.options.linkHandler = {
allowNonHttpProtocols: true,
activate: (event, uri) => {
if (!this.willHandleEvent(event)) {
return
}
this.platform.openExternal(uri)
const url = parseURL(uri)
if (!url) {
return
}
// A file: URL with a host is a UNC path - opening it would reach out
// over SMB to a server the remote side chose. Only allow local files.
const isLocalFile = url.protocol === 'file:' && !url.host
if (!['http:', 'https:'].includes(url.protocol) && !isLocalFile) {
return
}
this.platform.openExternal(url.href)
},
}
@@ -38,6 +57,7 @@ export class LinkHighlighterDecorator extends TerminalDecorator {
continue
}
handler.handle(await handler.convert(uri, tab), tab)
return
}
}
+1 -1
View File
@@ -93,7 +93,7 @@ export class UnixFileHandler extends BaseFileHandler {
@Injectable()
export class WindowsFileHandler extends BaseFileHandler {
regex = /(([a-zA-Z]:|\\|~)\\[\w\-()\\\.]{1,1024}|"([a-zA-Z]:|\\)\\[\w\s\-()\\\.]{1,1024}")/
regex = /(([a-zA-Z]:|\\|~)[\\/][\w\-()\\/.]{1,1024}|"([a-zA-Z]:|\\)[\\/][\w\s\-()\\/.]{1,1024}")/
constructor (
protected toastr: ToastrService,