diff --git a/src/blameAnnotationFormatter.ts b/src/blameAnnotationFormatter.ts index 189b8fc..b4649ef 100644 --- a/src/blameAnnotationFormatter.ts +++ b/src/blameAnnotationFormatter.ts @@ -9,6 +9,11 @@ export const defaultRelativeDateLength = 13; export const defaultAuthorLength = 16; export const defaultMessageLength = 32; +export const cssEllipse = '\\2026'; +export const cssIndent = '\\02759'; +export const cssSeparator = '\\2022'; +export const cssSpace = '\\00a0'; + export enum BlameAnnotationFormat { Constrained, Unconstrained @@ -18,16 +23,15 @@ export default class BlameAnnotationFormatter { static getAnnotation(config: IBlameConfig, commit: GitCommit, format: BlameAnnotationFormat) { const sha = commit.sha.substring(0, defaultShaLength); - const message = this.getMessage(config, commit, format === BlameAnnotationFormat.Unconstrained ? 0 : defaultMessageLength); + let message = this.getMessage(config, commit, format === BlameAnnotationFormat.Unconstrained ? 0 : defaultMessageLength); if (format === BlameAnnotationFormat.Unconstrained) { const authorAndDate = this.getAuthorAndDate(config, commit, 'MMMM Do, YYYY h:MMa'); if (config.annotation.sha) { - return `${sha}${(authorAndDate ? `\\00a0\\2022\\00a0 ${authorAndDate}` : '')}${(message ? `\\00a0\\2022\\00a0 ${message}` : '')}`; + message = `${sha}${(authorAndDate ? ` ${cssSeparator} ${authorAndDate}` : '')}${(message ? ` ${cssSeparator} ${message}` : '')}`; } - - if (config.annotation.author || config.annotation.date) { - return `${authorAndDate}${(message ? `\\00a0\\2022\\00a0 ${message}` : '')}`; + else if (config.annotation.author || config.annotation.date) { + message = `${authorAndDate}${(message ? ` ${cssSeparator} ${message}` : '')}`; } return message; @@ -36,15 +40,13 @@ export default class BlameAnnotationFormatter { const author = this.getAuthor(config, commit, defaultAuthorLength); const date = this.getDate(config, commit, 'MM/DD/YYYY', true); if (config.annotation.sha) { - return `${sha}${(author ? `\\00a0\\2022\\00a0 ${author}` : '')}${(date ? `\\00a0\\2022\\00a0 ${date}` : '')}${(message ? `\\00a0\\2022\\00a0 ${message}` : '')}`; + message = `${sha}${(author ? ` ${cssSeparator} ${author}` : '')}${(date ? ` ${cssSeparator} ${date}` : '')}${(message ? ` ${cssSeparator} ${message}` : '')}`; } - - if (config.annotation.author) { - return `${author}${(date ? `\\00a0\\2022\\00a0 ${date}` : '')}${(message ? `\\00a0\\2022\\00a0 ${message}` : '')}`; + else if (config.annotation.author) { + message = `${author}${(date ? ` ${cssSeparator} ${date}` : '')}${(message ? ` ${cssSeparator} ${message}` : '')}`; } - - if (config.annotation.date) { - return `${date}${(message ? `\\00a0\\2022\\00a0 ${message}` : '')}`; + else if (config.annotation.date) { + message = `${date}${(message ? ` ${cssSeparator} ${message}` : '')}`; } return message; @@ -80,10 +82,10 @@ export default class BlameAnnotationFormatter { if (!truncateTo) return author; if (author.length > truncateTo) { - return `${author.substring(0, truncateTo - 1)}\\2026`; + return `${author.substring(0, truncateTo - cssEllipse.length)}${cssEllipse}`; } - return author + '\\00a0'.repeat(truncateTo - author.length); + return author + `${cssSpace}`.repeat(truncateTo - author.length); } static getDate(config: IBlameConfig, commit: GitCommit, format?: string, truncate: boolean = false, force: boolean = false) { @@ -96,10 +98,10 @@ export default class BlameAnnotationFormatter { const truncateTo = config.annotation.date === 'relative' ? defaultRelativeDateLength : defaultAbsoluteDateLength; if (date.length > truncateTo) { - return `${date.substring(0, truncateTo - 1)}\\2026`; + return `${date.substring(0, truncateTo - cssEllipse.length)}${cssEllipse}`; } - return date + '\\00a0'.repeat(truncateTo - date.length); + return date + `${cssSpace}`.repeat(truncateTo - date.length); } static getMessage(config: IBlameConfig, commit: GitCommit, truncateTo: number = 0, force: boolean = false) { @@ -107,7 +109,7 @@ export default class BlameAnnotationFormatter { let message = commit.message; if (truncateTo && message.length > truncateTo) { - return `${message.substring(0, truncateTo - 1)}\\2026`; + return `${message.substring(0, truncateTo - cssEllipse.length)}${cssEllipse}`; } return message; diff --git a/src/blameAnnotationProvider.ts b/src/blameAnnotationProvider.ts index 83e571d..7fd42ea 100644 --- a/src/blameAnnotationProvider.ts +++ b/src/blameAnnotationProvider.ts @@ -1,7 +1,7 @@ 'use strict'; import { Iterables } from './system'; import { DecorationInstanceRenderOptions, DecorationOptions, DecorationRenderOptions, Disposable, ExtensionContext, OverviewRulerLane, Range, TextDocument, TextEditor, TextEditorDecorationType, TextEditorSelectionChangeEvent, window, workspace } from 'vscode'; -import BlameAnnotationFormatter, { BlameAnnotationFormat, defaultShaLength, defaultAuthorLength } from './blameAnnotationFormatter'; +import BlameAnnotationFormatter, { BlameAnnotationFormat, cssIndent, defaultShaLength, defaultAuthorLength } from './blameAnnotationFormatter'; import { TextDocumentComparer } from './comparers'; import { BlameAnnotationStyle, IBlameConfig } from './configuration'; import GitProvider, { GitUri, IGitBlame } from './gitProvider'; @@ -180,13 +180,13 @@ export class BlameAnnotationProvider extends Disposable { gutter = commit.sha.substring(0, defaultShaLength); break; case 1: - gutter = `\\02759\\00a0 ${BlameAnnotationFormatter.getAuthor(this._config, commit, defaultAuthorLength, true)}`; + gutter = `${cssIndent} ${BlameAnnotationFormatter.getAuthor(this._config, commit, defaultAuthorLength, true)}`; break; case 2: - gutter = `\\02759\\00a0 ${BlameAnnotationFormatter.getDate(this._config, commit, 'MM/DD/YYYY', true, true)}`; + gutter = `${cssIndent} ${BlameAnnotationFormatter.getDate(this._config, commit, 'MM/DD/YYYY', true, true)}`; break; default: - gutter = '\\02759'; + gutter = `${cssIndent}`; break; } }