Skip to content

Commit fb867a9

Browse files
authored
Merge pull request #4973 from Tyriar/spacing
Fix spacing issue when measuring before element is attached
2 parents 6a281bd + 8ef3c10 commit fb867a9

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/browser/renderer/dom/WidthCache.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,14 @@ export class WidthCache implements IDisposable {
134134
public get(c: string, bold: boolean | number, italic: boolean | number): number {
135135
let cp = 0;
136136
if (!bold && !italic && c.length === 1 && (cp = c.charCodeAt(0)) < WidthCacheSettings.FLAT_SIZE) {
137-
return this._flat[cp] !== WidthCacheSettings.FLAT_UNSET
138-
? this._flat[cp]
139-
: (this._flat[cp] = this._measure(c, 0));
137+
if (this._flat[cp] !== WidthCacheSettings.FLAT_UNSET) {
138+
return this._flat[cp];
139+
}
140+
const width = this._measure(c, 0);
141+
if (width > 0) {
142+
this._flat[cp] = width;
143+
}
144+
return width;
140145
}
141146
let key = c;
142147
if (bold) key += 'B';
@@ -147,7 +152,9 @@ export class WidthCache implements IDisposable {
147152
if (bold) variant |= FontVariant.BOLD;
148153
if (italic) variant |= FontVariant.ITALIC;
149154
width = this._measure(c, variant);
150-
this._holey!.set(key, width);
155+
if (width > 0) {
156+
this._holey!.set(key, width);
157+
}
151158
}
152159
return width;
153160
}

0 commit comments

Comments
 (0)