@@ -17,6 +17,7 @@ export const enum RenderWhitespace {
1717
1818export class RenderLineInput {
1919
20+ public readonly fontIsMonospace : boolean ;
2021 public readonly lineContent : string ;
2122 public readonly mightContainRTL : boolean ;
2223 public readonly fauxIndentLength : number ;
@@ -29,6 +30,7 @@ export class RenderLineInput {
2930 public readonly renderControlCharacters : boolean ;
3031
3132 constructor (
33+ fontIsMonospace : boolean ,
3234 lineContent : string ,
3335 mightContainRTL : boolean ,
3436 fauxIndentLength : number ,
@@ -40,6 +42,7 @@ export class RenderLineInput {
4042 renderWhitespace : 'none' | 'boundary' | 'all' ,
4143 renderControlCharacters : boolean ,
4244 ) {
45+ this . fontIsMonospace = fontIsMonospace ;
4346 this . lineContent = lineContent ;
4447 this . mightContainRTL = mightContainRTL ;
4548 this . fauxIndentLength = fauxIndentLength ;
@@ -60,7 +63,8 @@ export class RenderLineInput {
6063
6164 public equals ( other : RenderLineInput ) : boolean {
6265 return (
63- this . lineContent === other . lineContent
66+ this . fontIsMonospace === other . fontIsMonospace
67+ && this . lineContent === other . lineContent
6468 && this . mightContainRTL === other . mightContainRTL
6569 && this . fauxIndentLength === other . fauxIndentLength
6670 && this . tabSize === other . tabSize
@@ -225,6 +229,7 @@ export function renderViewLine(input: RenderLineInput): RenderLineOutput {
225229
226230class ResolvedRenderLineInput {
227231 constructor (
232+ public readonly fontIsMonospace : boolean ,
228233 public readonly lineContent : string ,
229234 public readonly len : number ,
230235 public readonly isOverflowing : boolean ,
@@ -241,6 +246,7 @@ class ResolvedRenderLineInput {
241246}
242247
243248function resolveRenderLineInput ( input : RenderLineInput ) : ResolvedRenderLineInput {
249+ const fontIsMonospace = input . fontIsMonospace ;
244250 const lineContent = input . lineContent ;
245251
246252 let isOverflowing : boolean ;
@@ -256,7 +262,7 @@ function resolveRenderLineInput(input: RenderLineInput): ResolvedRenderLineInput
256262
257263 let tokens = removeOverflowing ( input . lineTokens , len ) ;
258264 if ( input . renderWhitespace === RenderWhitespace . All || input . renderWhitespace === RenderWhitespace . Boundary ) {
259- tokens = _applyRenderWhitespace ( lineContent , len , tokens , input . fauxIndentLength , input . tabSize , input . renderWhitespace === RenderWhitespace . Boundary ) ;
265+ tokens = _applyRenderWhitespace ( lineContent , len , tokens , input . fauxIndentLength , input . tabSize , fontIsMonospace , input . renderWhitespace === RenderWhitespace . Boundary ) ;
260266 }
261267 if ( input . lineDecorations . length > 0 ) {
262268 tokens = _applyInlineDecorations ( lineContent , len , tokens , input . lineDecorations ) ;
@@ -270,6 +276,7 @@ function resolveRenderLineInput(input: RenderLineInput): ResolvedRenderLineInput
270276 }
271277
272278 return new ResolvedRenderLineInput (
279+ fontIsMonospace ,
273280 lineContent ,
274281 len ,
275282 isOverflowing ,
@@ -351,7 +358,7 @@ function splitLargeTokens(tokens: ViewLineToken[]): ViewLineToken[] {
351358 * Moreover, a token is created for every visual indent because on some fonts the glyphs used for rendering whitespace (→ or ·) do not have the same width as .
352359 * The rendering phase will generate `style="width:..."` for these tokens.
353360 */
354- function _applyRenderWhitespace ( lineContent : string , len : number , tokens : ViewLineToken [ ] , fauxIndentLength : number , tabSize : number , onlyBoundary : boolean ) : ViewLineToken [ ] {
361+ function _applyRenderWhitespace ( lineContent : string , len : number , tokens : ViewLineToken [ ] , fauxIndentLength : number , tabSize : number , fontIsMonospace : boolean , onlyBoundary : boolean ) : ViewLineToken [ ] {
355362
356363 let result : ViewLineToken [ ] = [ ] , resultLen = 0 ;
357364 let tokenIndex = 0 ;
@@ -413,7 +420,7 @@ function _applyRenderWhitespace(lineContent: string, len: number, tokens: ViewLi
413420
414421 if ( wasInWhitespace ) {
415422 // was in whitespace token
416- if ( ! isInWhitespace || tmpIndent >= tabSize ) {
423+ if ( ! isInWhitespace || ( ! fontIsMonospace && tmpIndent >= tabSize ) ) {
417424 // leaving whitespace token or entering a new indent
418425 result [ resultLen ++ ] = new ViewLineToken ( charIndex , 'vs-whitespace' ) ;
419426 tmpIndent = tmpIndent % tabSize ;
@@ -499,6 +506,7 @@ function _applyInlineDecorations(lineContent: string, len: number, tokens: ViewL
499506 * Notice how all the needed data is fully resolved and passed in (i.e. no other calls).
500507 */
501508function _renderLine ( input : ResolvedRenderLineInput ) : RenderLineOutput {
509+ const fontIsMonospace = input . fontIsMonospace ;
502510 const lineContent = input . lineContent ;
503511 const len = input . len ;
504512 const isOverflowing = input . isOverflowing ;
@@ -555,7 +563,11 @@ function _renderLine(input: ResolvedRenderLineInput): RenderLineOutput {
555563 }
556564
557565 characterMapping . setPartLength ( tokenIndex , partContentCnt ) ;
558- out += `<span class="${ tokenType } " style="width:${ spaceWidth * partContentCnt } px">${ partContent } </span>` ;
566+ if ( fontIsMonospace ) {
567+ out += `<span class="${ tokenType } ">${ partContent } </span>` ;
568+ } else {
569+ out += `<span class="${ tokenType } " style="width:${ spaceWidth * partContentCnt } px">${ partContent } </span>` ;
570+ }
559571
560572 } else {
561573
0 commit comments