From 62c5094b06c866df90ba7f6e928c7e43968d645e Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 8 Feb 2017 12:18:34 -0500 Subject: [PATCH] Adds control over annotation characters --- package.json | 20 ++++++++++++++++++++ src/blameAnnotationFormatter.ts | 21 +++++++++++++++------ src/configuration.ts | 6 ++++++ src/extension.ts | 8 ++++++-- 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index fc99b04..c094954 100644 --- a/package.json +++ b/package.json @@ -88,6 +88,26 @@ ], "description": "Specifies whether and how to show blame annotations on the active line. `off` - no annotation. `inline` - adds a trailing annotation to the active line. `hover` - adds hover annotation to the active line. `both` - adds both `inline` and `hover` annotations" }, + "gitlens.blame.annotation.characters.ellipse": { + "type": "string", + "default": "\\2026", + "description": "Specifies the ellipse character to use in blame annotations" + }, + "gitlens.blame.annotation.characters.indent": { + "type": "string", + "default": "\\2759", + "description": "Specifies the indent character to use in `compact` blame annotations" + }, + "gitlens.blame.annotation.characters.padding": { + "type": "string", + "default": "\\00a0", + "description": "Specifies the padding character (typically a non-breaking space) to use in blame annotations" + }, + "gitlens.blame.annotation.characters.separator": { + "type": "string", + "default": "\\2022", + "description": "Specifies the separator character to use in blame annotations" + }, "gitlens.codeLens.visibility": { "type": "string", "default": "auto", diff --git a/src/blameAnnotationFormatter.ts b/src/blameAnnotationFormatter.ts index b4649ef..daca0d7 100644 --- a/src/blameAnnotationFormatter.ts +++ b/src/blameAnnotationFormatter.ts @@ -9,10 +9,17 @@ 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 let cssEllipse = '\\2026'; +export let cssIndent = '\\2759'; +export let cssSeparator = '\\2022'; +export let cssPadding = '\\00a0'; + +export function configureCssCharacters(config: IBlameConfig) { + cssEllipse = config.annotation.characters.ellipse || cssEllipse; + cssIndent = config.annotation.characters.indent || cssIndent; + cssPadding = config.annotation.characters.padding || cssPadding; + cssSeparator = config.annotation.characters.separator || cssSeparator; +} export enum BlameAnnotationFormat { Constrained, @@ -85,7 +92,8 @@ export default class BlameAnnotationFormatter { return `${author.substring(0, truncateTo - cssEllipse.length)}${cssEllipse}`; } - return author + `${cssSpace}`.repeat(truncateTo - author.length); + if (force) return author; // Don't pad when just asking for the value + return author + `${cssPadding}`.repeat(truncateTo - author.length); } static getDate(config: IBlameConfig, commit: GitCommit, format?: string, truncate: boolean = false, force: boolean = false) { @@ -101,7 +109,8 @@ export default class BlameAnnotationFormatter { return `${date.substring(0, truncateTo - cssEllipse.length)}${cssEllipse}`; } - return date + `${cssSpace}`.repeat(truncateTo - date.length); + if (force) return date; // Don't pad when just asking for the value + return date + `${cssPadding}`.repeat(truncateTo - date.length); } static getMessage(config: IBlameConfig, commit: GitCommit, truncateTo: number = 0, force: boolean = false) { diff --git a/src/configuration.ts b/src/configuration.ts index 906d0d8..db8b957 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -16,6 +16,12 @@ export interface IBlameConfig { date: 'off' | 'relative' | 'absolute'; message: boolean; activeLine: 'off' | 'inline' | 'hover' | 'both'; + characters: { + ellipse: string; + indent: string; + padding: string; + separator: string; + } }; } diff --git a/src/extension.ts b/src/extension.ts index 8389373..2671377 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -2,6 +2,7 @@ import { ExtensionContext, languages, window, workspace } from 'vscode'; import BlameAnnotationController from './blameAnnotationController'; import BlameStatusBarController from './blameStatusBarController'; +import { configureCssCharacters } from './blameAnnotationFormatter'; import DiffLineWithPreviousCommand from './commands/diffLineWithPrevious'; import DiffLineWithWorkingCommand from './commands/diffLineWithWorking'; import DiffWithPreviousCommand from './commands/diffWithPrevious'; @@ -13,7 +14,7 @@ import ShowQuickFileHistoryCommand from './commands/showQuickFileHistory'; import ShowQuickRepoHistoryCommand from './commands/showQuickRepoHistory'; import ToggleBlameCommand from './commands/toggleBlame'; import ToggleCodeLensCommand from './commands/toggleCodeLens'; -import { IAdvancedConfig } from './configuration'; +import { IAdvancedConfig, IBlameConfig } from './configuration'; import { WorkspaceState } from './constants'; import GitContentProvider from './gitContentProvider'; import GitProvider, { Git } from './gitProvider'; @@ -32,7 +33,10 @@ export async function activate(context: ExtensionContext) { const rootPath = workspace.rootPath.replace(/\\/g, '/'); Logger.log(`GitLens active: ${rootPath}`); - const gitPath = workspace.getConfiguration('gitlens').get('advanced').git; + const config = workspace.getConfiguration('gitlens'); + const gitPath = config.get('advanced').git; + + configureCssCharacters(config.get('blame')); let repoPath: string; try {