5
5
6
6
import { getActiveWindow } from '../../../../base/browser/dom.js' ;
7
7
import { CharCode } from '../../../../base/common/charCode.js' ;
8
+ import { BugIndicatingError } from '../../../../base/common/errors.js' ;
8
9
import { Emitter , Event } from '../../../../base/common/event.js' ;
9
10
import { Disposable , dispose , MutableDisposable , toDisposable } from '../../../../base/common/lifecycle.js' ;
10
11
import { ThreeKeyMap } from '../../../../base/common/map.js' ;
@@ -22,7 +23,7 @@ export interface ITextureAtlasOptions {
22
23
}
23
24
24
25
export class TextureAtlas extends Disposable {
25
- private _colorMap ! : string [ ] ;
26
+ private _colorMap ? : string [ ] ;
26
27
private readonly _warmUpTask : MutableDisposable < IdleTaskQueue > = this . _register ( new MutableDisposable ( ) ) ;
27
28
private readonly _warmedUpRasterizers = new Set < number > ( ) ;
28
29
private readonly _allocatorType : AllocatorType ;
@@ -60,7 +61,9 @@ export class TextureAtlas extends Disposable {
60
61
this . _allocatorType = options ?. allocatorType ?? 'slab' ;
61
62
62
63
this . _register ( Event . runAndSubscribe ( this . _themeService . onDidColorThemeChange , ( ) => {
63
- // TODO: Clear entire atlas on theme change
64
+ if ( this . _colorMap ) {
65
+ this . clear ( ) ;
66
+ }
64
67
this . _colorMap = this . _themeService . getColorTheme ( ) . tokenColorMap ;
65
68
} ) ) ;
66
69
@@ -147,29 +150,33 @@ export class TextureAtlas extends Disposable {
147
150
* is distrubuted over multiple idle callbacks to avoid blocking the main thread.
148
151
*/
149
152
private _warmUpAtlas ( rasterizer : IGlyphRasterizer ) : void {
153
+ const colorMap = this . _colorMap ;
154
+ if ( ! colorMap ) {
155
+ throw new BugIndicatingError ( 'Cannot warm atlas without color map' ) ;
156
+ }
150
157
this . _warmUpTask . value ?. clear ( ) ;
151
158
const taskQueue = this . _warmUpTask . value = new IdleTaskQueue ( ) ;
152
159
// Warm up using roughly the larger glyphs first to help optimize atlas allocation
153
160
// A-Z
154
161
for ( let code = CharCode . A ; code <= CharCode . Z ; code ++ ) {
155
162
taskQueue . enqueue ( ( ) => {
156
- for ( const fgColor of this . _colorMap . keys ( ) ) {
163
+ for ( const fgColor of colorMap . keys ( ) ) {
157
164
this . getGlyph ( rasterizer , String . fromCharCode ( code ) , ( fgColor << MetadataConsts . FOREGROUND_OFFSET ) & MetadataConsts . FOREGROUND_MASK ) ;
158
165
}
159
166
} ) ;
160
167
}
161
168
// a-z
162
169
for ( let code = CharCode . a ; code <= CharCode . z ; code ++ ) {
163
170
taskQueue . enqueue ( ( ) => {
164
- for ( const fgColor of this . _colorMap . keys ( ) ) {
171
+ for ( const fgColor of colorMap . keys ( ) ) {
165
172
this . getGlyph ( rasterizer , String . fromCharCode ( code ) , ( fgColor << MetadataConsts . FOREGROUND_OFFSET ) & MetadataConsts . FOREGROUND_MASK ) ;
166
173
}
167
174
} ) ;
168
175
}
169
176
// Remaining ascii
170
177
for ( let code = CharCode . ExclamationMark ; code <= CharCode . Tilde ; code ++ ) {
171
178
taskQueue . enqueue ( ( ) => {
172
- for ( const fgColor of this . _colorMap . keys ( ) ) {
179
+ for ( const fgColor of colorMap . keys ( ) ) {
173
180
this . getGlyph ( rasterizer , String . fromCharCode ( code ) , ( fgColor << MetadataConsts . FOREGROUND_OFFSET ) & MetadataConsts . FOREGROUND_MASK ) ;
174
181
}
175
182
} ) ;
0 commit comments