diff --git a/package.json b/package.json index 2df7e84..717cf1b 100644 --- a/package.json +++ b/package.json @@ -574,7 +574,7 @@ }, "gitlens.currentLine.format": { "type": "string", - "default": "${message|50? • }${author}${\" via \"pullRequest}, ${agoOrDate}", + "default": "${author, }${agoOrDate}${' via 'pullRequest}${ • message|50?}", "markdownDescription": "Specifies the format of the current line blame annotation. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs. Date formatting is controlled by the `#gitlens.currentLine.dateFormat#` setting", "scope": "window" }, @@ -921,7 +921,7 @@ }, "gitlens.hovers.detailsMarkdownFormat": { "type": "string", - "default": "${avatar}  __${author}__${\" via \"pullRequest}, ${ago}   _(${date})_ \n\n${message}\n\n${commands}", + "default": "${avatar}  __${author}__, ${ago}${' via 'pullRequest}   _(${date})_ \n\n${message}\n\n${commands}", "markdownDescription": "Specifies the format (in markdown) of the _commit details_ hover. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs", "scope": "window" }, diff --git a/src/system/string.ts b/src/system/string.ts index 3d6a0c3..e313806 100644 --- a/src/system/string.ts +++ b/src/system/string.ts @@ -75,8 +75,11 @@ export function getSuperscript(num: number) { const driveLetterNormalizeRegex = /(?<=^\/?)([A-Z])(?=:\/)/; const pathNormalizeRegex = /\\/g; const pathStripTrailingSlashRegex = /\/$/g; -const tokenRegex = /\$\{(".*?"|\W*)?([^|]*?)(?:\|(\d+)(-|\?)?)?(".*?"|\W*)?\}/g; -const tokenSanitizeRegex = /\$\{(?:".*?"|\W*)?(\w*?)(?:".*?"|[\W\d]*)\}/g; +const tokenRegex = /\$\{('.*?[^\\]'|\W*)?([^|]*?)(?:\|(\d+)(-|\?)?)?('.*?[^\\]'|\W*)?\}/g; +const tokenSanitizeRegex = /\$\{(?:'.*?[^\\]'|\W*)?(\w*?)(?:'.*?[^\\]'|[\W\d]*)\}/g; +const tokenGroupCharacter = "'"; +const tokenGroupCharacterEscapedRegex = /(\\')/g; +const tokenGroupRegex = /^'?(.*?)'?$/; export interface TokenOptions { collapseWhitespace: boolean; @@ -94,17 +97,33 @@ export function getTokensFromTemplate(template: string) { match = tokenRegex.exec(template); if (match == null) break; - const [, prefix, key, truncateTo, option, suffix] = match; + // eslint-disable-next-line prefer-const + let [, prefix, key, truncateTo, option, suffix] = match; + // Check for a prefix group + if (prefix != null) { + match = tokenGroupRegex.exec(prefix); + if (match != null) { + [, prefix] = match; + prefix = prefix.replace(tokenGroupCharacterEscapedRegex, tokenGroupCharacter); + } + } + + // Check for a suffix group + if (suffix != null) { + match = tokenGroupRegex.exec(suffix); + if (match != null) { + [, suffix] = match; + suffix = suffix.replace(tokenGroupCharacterEscapedRegex, tokenGroupCharacter); + } + } + tokens.push({ key: key, options: { collapseWhitespace: option === '?', padDirection: option === '-' ? 'left' : 'right', - prefix: - prefix?.length > 1 && prefix?.startsWith('"') && prefix?.endsWith('"') - ? prefix.substr(1, prefix.length - 2) - : prefix, - suffix: suffix, + prefix: prefix || undefined, + suffix: suffix || undefined, truncateTo: truncateTo == null ? undefined : parseInt(truncateTo, 10), }, }); diff --git a/src/views/nodes/commitFileNode.ts b/src/views/nodes/commitFileNode.ts index 8fe974e..4466150 100644 --- a/src/views/nodes/commitFileNode.ts +++ b/src/views/nodes/commitFileNode.ts @@ -169,9 +169,9 @@ export class CommitFileNode extends ViewRefFileNode { return CommitFormatter.fromTemplate( this.commit.isUncommitted ? `\${author} ${GlyphChars.Dash} \${id}\n${status}\n\${ago} (\${date})` - : `\${author}\${ (email)}\${" via "pullRequest} ${ - GlyphChars.Dash - } \${id}\n${status}\n\${ago} (\${date})\${\n\nmessage}${this.commit.getFormattedDiffStatus({ + : `\${author}\${ (email)} ${GlyphChars.Dash} \${id}${ + this._options.unpublished ? ' (unpublished)' : '' + }\n${status}\n\${ago} (\${date})\${\n\nmessage}${this.commit.getFormattedDiffStatus({ expand: true, prefix: '\n\n', separator: '\n', diff --git a/src/views/nodes/commitNode.ts b/src/views/nodes/commitNode.ts index d1f3ead..af162c4 100644 --- a/src/views/nodes/commitNode.ts +++ b/src/views/nodes/commitNode.ts @@ -46,7 +46,7 @@ export class CommitNode extends ViewRefNode