Skip to content

Commit 355eea2

Browse files
committed
linked text: class
1 parent f1c6f2c commit 355eea2

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/vs/base/browser/linkedText.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,25 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { memoize } from 'vs/base/common/decorators';
7+
68
export interface ILink {
79
readonly label: string;
810
readonly href: string;
911
readonly title?: string;
1012
}
1113

1214
export type LinkedTextNode = string | ILink;
13-
export type LinkedText = LinkedTextNode[];
15+
16+
export class LinkedText {
17+
18+
constructor(readonly nodes: LinkedTextNode[]) { }
19+
20+
@memoize
21+
toString(): string {
22+
return this.nodes.map(node => typeof node === 'string' ? node : node.label).join('');
23+
}
24+
}
1425

1526
const LINK_REGEX = /\[([^\]]+)\]\(((?:https?:\/\/|command:)[^\)\s]+)(?: "([^"]+)")?\)/gi;
1627

@@ -40,5 +51,5 @@ export function parseLinkedText(text: string): LinkedText {
4051
result.push(text.substring(index));
4152
}
4253

43-
return result;
54+
return new LinkedText(result);
4455
}

src/vs/workbench/browser/parts/views/viewPaneContainer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,10 @@ export abstract class ViewPane extends Pane implements IView {
402402
const p = append(this.viewWelcomeContainer, $('p'));
403403
const linkedText = parseLinkedText(line);
404404

405-
for (const node of linkedText) {
405+
for (const node of linkedText.nodes) {
406406
if (typeof node === 'string') {
407407
append(p, document.createTextNode(node));
408-
} else if (linkedText.length === 1) {
408+
} else if (linkedText.nodes.length === 1) {
409409
const button = new Button(p, { title: node.title });
410410
button.label = node.label;
411411
button.onDidClick(_ => this.openerService.open(node.href), null, disposables);

0 commit comments

Comments
 (0)