Parcourir la source

Fixes #27 unicode in annotations is broken

main
Eric Amodio il y a 7 ans
Parent
révision
9da3d26fc6
2 fichiers modifiés avec 21 ajouts et 22 suppressions
  1. +4
    -4
      package.json
  2. +17
    -18
      src/blameAnnotationFormatter.ts

+ 4
- 4
package.json Voir le fichier

@ -101,22 +101,22 @@
},
"gitlens.blame.annotation.characters.ellipse": {
"type": "string",
"default": "\\2026",
"default": "\u2026",
"description": "Specifies the ellipse character to use in blame annotations"
},
"gitlens.blame.annotation.characters.indent": {
"type": "string",
"default": "\\2759",
"default": "\u2759",
"description": "Specifies the indent character to use in `compact` blame annotations"
},
"gitlens.blame.annotation.characters.padding": {
"type": "string",
"default": "\\00a0",
"default": "\u00a0",
"description": "Specifies the padding character (typically a non-breaking space) to use in blame annotations"
},
"gitlens.blame.annotation.characters.separator": {
"type": "string",
"default": "\\2022",
"default": "\u2022",
"description": "Specifies the separator character to use in blame annotations"
},
"gitlens.codeLens.visibility": {

+ 17
- 18
src/blameAnnotationFormatter.ts Voir le fichier

@ -9,22 +9,21 @@ export const defaultRelativeDateLength = 13;
export const defaultAuthorLength = 16;
export const defaultMessageLength = 32;
export let cssEllipse = '\\002026';
export let cssIndent = '\\002759';
export let cssSeparator = '\\002022';
export let cssPadding = '\\0000a0';
const defaultCssEllipse = '\u2026';
const defaultCssIndent = '\u2759';
const defaultCssPadding = '\u00a0';
const defaultCssSeparator = '\u2022';
let cssEllipseLength: number = 1;
const cssUnicodeMatcher = /\\[0-9a-fA-F]{1,6}/;
export let cssEllipse = defaultCssEllipse;
export let cssIndent = defaultCssIndent;
export let cssPadding = defaultCssPadding;
export let cssSeparator = defaultCssSeparator;
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;
cssEllipseLength = cssUnicodeMatcher.test(cssEllipse) ? 1 : cssEllipse.length;
cssEllipse = config.annotation.characters.ellipse || defaultCssEllipse;
cssIndent = config.annotation.characters.indent || defaultCssIndent;
cssPadding = config.annotation.characters.padding || defaultCssSeparator;
cssSeparator = config.annotation.characters.separator || defaultCssSeparator;
}
export enum BlameAnnotationFormat {
@ -95,11 +94,11 @@ export default class BlameAnnotationFormatter {
if (!truncateTo) return author;
if (author.length > truncateTo) {
return `${author.substring(0, truncateTo - cssEllipseLength)}${cssEllipse}`;
return `${author.substring(0, truncateTo - cssEllipse.length)}${cssEllipse}`;
}
if (force) return author; // Don't pad when just asking for the value
return author + `${cssPadding}`.repeat(truncateTo - author.length);
return author + cssPadding.repeat(truncateTo - author.length);
}
static getDate(config: IBlameConfig, commit: GitCommit, format?: string, truncate: boolean = false, force: boolean = false) {
@ -112,11 +111,11 @@ export default class BlameAnnotationFormatter {
const truncateTo = config.annotation.date === 'relative' ? defaultRelativeDateLength : defaultAbsoluteDateLength;
if (date.length > truncateTo) {
return `${date.substring(0, truncateTo - cssEllipseLength)}${cssEllipse}`;
return `${date.substring(0, truncateTo - cssEllipse.length)}${cssEllipse}`;
}
if (force) return date; // Don't pad when just asking for the value
return date + `${cssPadding}`.repeat(truncateTo - date.length);
return date + cssPadding.repeat(truncateTo - date.length);
}
static getMessage(config: IBlameConfig, commit: GitCommit, truncateTo: number = 0, force: boolean = false) {
@ -124,7 +123,7 @@ export default class BlameAnnotationFormatter {
let message = commit.isUncommitted ? 'Uncommited change' : commit.message;
if (truncateTo && message.length > truncateTo) {
return `${message.substring(0, truncateTo - cssEllipseLength)}${cssEllipse}`;
return `${message.substring(0, truncateTo - cssEllipse.length)}${cssEllipse}`;
}
return message;

Chargement…
Annuler
Enregistrer