33 DecorationOptions ,
44 MarkdownString ,
55 ThemableDecorationRenderOptions ,
6- ThemeColor
6+ ThemeColor ,
7+ workspace
78} from 'vscode' ;
89import {
910 DiffWithCommand ,
@@ -272,26 +273,26 @@ export class Annotations {
272273 format : string ,
273274 options : ICommitFormatOptions
274275 ) : IRenderOptions {
275- // Get the width of all the tokens, assuming there there is a cap (bail if not)
276- let width = 0 ;
276+ // Get the character count of all the tokens, assuming there there is a cap (bail if not)
277+ let chars = 0 ;
277278 for ( const token of Objects . values ( options . tokenOptions ! ) ) {
278279 if ( token === undefined ) continue ;
279280
280281 // If any token is uncapped, kick out and set no max
281282 if ( token . truncateTo == null ) {
282- width = - 1 ;
283+ chars = - 1 ;
283284 break ;
284285 }
285286
286- width += token . truncateTo ;
287+ chars += token . truncateTo ;
287288 }
288289
289- if ( width >= 0 ) {
290- // Add the width of the template string (without tokens)
291- width += Strings . getWidth ( Strings . interpolate ( format , undefined ) ) ;
292- // If we have some width , add a bit of padding
293- if ( width > 0 ) {
294- width += 3 ;
290+ if ( chars >= 0 ) {
291+ // Add the chars of the template string (without tokens)
292+ chars += Strings . getWidth ( Strings . interpolate ( format , undefined ) ) ;
293+ // If we have chars , add a bit of padding
294+ if ( chars > 0 ) {
295+ chars += 3 ;
295296 }
296297 }
297298
@@ -302,6 +303,17 @@ export class Annotations {
302303 borderWidth = heatmap . location === 'left' ? '0 0 0 2px' : '0 2px 0 0' ;
303304 }
304305
306+ let width ;
307+ if ( chars >= 0 ) {
308+ const spacing = workspace . getConfiguration ( 'editor' ) . get < number > ( 'letterSpacing' ) ;
309+ if ( spacing != null && spacing !== 0 ) {
310+ width = `calc(${ chars } ch + ${ Math . round ( chars * spacing ) } px)` ;
311+ }
312+ else {
313+ width = `${ chars } ch` ;
314+ }
315+ }
316+
305317 return {
306318 backgroundColor : new ThemeColor ( 'gitlens.gutterBackgroundColor' ) ,
307319 borderStyle : borderStyle ,
@@ -310,9 +322,9 @@ export class Annotations {
310322 fontWeight : 'normal' ,
311323 fontStyle : 'normal' ,
312324 height : '100%' ,
313- margin : ' 0 26px -1px 0' ,
325+ margin : ` 0 26px -1px 0` ,
314326 textDecoration : separateLines ? 'overline solid rgba(0, 0, 0, .2)' : 'none' ,
315- width : width >= 0 ? ` ${ width } ch` : undefined ,
327+ width : width ,
316328 uncommittedColor : new ThemeColor ( 'gitlens.gutterUncommittedForegroundColor' )
317329 } as IRenderOptions ;
318330 }
0 commit comments