mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-16 10:58:34 -05:00
Fixes #135 - Full-width chars break gutter annotations
This commit is contained in:
@@ -61,7 +61,7 @@ export class GutterBlameAnnotationProvider extends BlameAnnotationProviderBase {
|
|||||||
gutter.renderOptions = { ...gutter.renderOptions };
|
gutter.renderOptions = { ...gutter.renderOptions };
|
||||||
gutter.renderOptions.before = {
|
gutter.renderOptions.before = {
|
||||||
...gutter.renderOptions.before,
|
...gutter.renderOptions.before,
|
||||||
...{ contentText: GlyphChars.Space.repeat(gutter.renderOptions!.before!.contentText!.length) }
|
...{ contentText: GlyphChars.Space.repeat(Strings.getWidth(gutter.renderOptions!.before!.contentText!)) }
|
||||||
};
|
};
|
||||||
|
|
||||||
if (separateLines) {
|
if (separateLines) {
|
||||||
|
|||||||
@@ -102,7 +102,23 @@ export namespace Strings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function truncate(s: string, truncateTo?: number) {
|
export function truncate(s: string, truncateTo?: number) {
|
||||||
if (!s || truncateTo === undefined || getWidth(s) <= truncateTo) return s;
|
if (!s || truncateTo === undefined) return s;
|
||||||
return `${s.substring(0, truncateTo - 1)}\u2026`;
|
|
||||||
|
const len = getWidth(s);
|
||||||
|
if (len <= truncateTo) return s;
|
||||||
|
if (len === s.length) return `${s.substring(0, truncateTo - 1)}\u2026`;
|
||||||
|
|
||||||
|
// Skip ahead to start as far as we can by assuming all the double-width characters won't be truncated
|
||||||
|
let chars = Math.floor(truncateTo / (len / s.length));
|
||||||
|
let count = getWidth(s.substring(0, chars));
|
||||||
|
while (count < truncateTo) {
|
||||||
|
count += getWidth(s[chars++]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count > truncateTo) {
|
||||||
|
chars--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${s.substring(0, chars)}\u2026`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user