未验证 提交 355eea22 编写于 作者: J Joao Moreno

linked text: class

上级 f1c6f2c2
......@@ -3,6 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { memoize } from 'vs/base/common/decorators';
export interface ILink {
readonly label: string;
readonly href: string;
......@@ -10,7 +12,16 @@ export interface ILink {
}
export type LinkedTextNode = string | ILink;
export type LinkedText = LinkedTextNode[];
export class LinkedText {
constructor(readonly nodes: LinkedTextNode[]) { }
@memoize
toString(): string {
return this.nodes.map(node => typeof node === 'string' ? node : node.label).join('');
}
}
const LINK_REGEX = /\[([^\]]+)\]\(((?:https?:\/\/|command:)[^\)\s]+)(?: "([^"]+)")?\)/gi;
......@@ -40,5 +51,5 @@ export function parseLinkedText(text: string): LinkedText {
result.push(text.substring(index));
}
return result;
return new LinkedText(result);
}
......@@ -402,10 +402,10 @@ export abstract class ViewPane extends Pane implements IView {
const p = append(this.viewWelcomeContainer, $('p'));
const linkedText = parseLinkedText(line);
for (const node of linkedText) {
for (const node of linkedText.nodes) {
if (typeof node === 'string') {
append(p, document.createTextNode(node));
} else if (linkedText.length === 1) {
} else if (linkedText.nodes.length === 1) {
const button = new Button(p, { title: node.title });
button.label = node.label;
button.onDidClick(_ => this.openerService.open(node.href), null, disposables);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册