mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 04:49:35 +00:00
linked text: class
This commit is contained in:
parent
f1c6f2c200
commit
355eea22ea
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue