@@ -17,6 +17,7 @@ import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService
1717import { getColors , IColorData } from 'vs/editor/contrib/colorPicker/color' ;
1818import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
1919import { ModelDecorationOptions } from 'vs/editor/common/model/textModel' ;
20+ import { TimeoutTimer } from 'vs/base/common/async' ;
2021
2122const MAX_DECORATORS = 500 ;
2223
@@ -29,7 +30,7 @@ export class ColorDetector implements IEditorContribution {
2930 private _globalToDispose : IDisposable [ ] = [ ] ;
3031 private _localToDispose : IDisposable [ ] = [ ] ;
3132 private _computePromise : TPromise < void > ;
32- private _timeoutPromise : TPromise < void > ;
33+ private _timeoutTimer : TimeoutTimer ;
3334
3435 private _decorationsIds : string [ ] = [ ] ;
3536 private _colorDatas = new Map < string , IColorData > ( ) ;
@@ -61,7 +62,7 @@ export class ColorDetector implements IEditorContribution {
6162 }
6263 } ) ) ;
6364
64- this . _timeoutPromise = null ;
65+ this . _timeoutTimer = null ;
6566 this . _computePromise = null ;
6667 this . _isEnabled = this . isEnabled ( ) ;
6768 this . onModelChanged ( ) ;
@@ -115,12 +116,12 @@ export class ColorDetector implements IEditorContribution {
115116 }
116117
117118 this . _localToDispose . push ( this . _editor . onDidChangeModelContent ( ( e ) => {
118- if ( ! this . _timeoutPromise ) {
119- this . _timeoutPromise = TPromise . timeout ( ColorDetector . RECOMPUTE_TIME ) ;
120- this . _timeoutPromise . then ( ( ) => {
121- this . _timeoutPromise = null ;
119+ if ( ! this . _timeoutTimer ) {
120+ this . _timeoutTimer = new TimeoutTimer ( ) ;
121+ this . _timeoutTimer . cancelAndSet ( ( ) => {
122+ this . _timeoutTimer = null ;
122123 this . beginCompute ( ) ;
123- } ) ;
124+ } , ColorDetector . RECOMPUTE_TIME ) ;
124125 }
125126 } ) ) ;
126127 this . beginCompute ( ) ;
@@ -135,9 +136,9 @@ export class ColorDetector implements IEditorContribution {
135136 }
136137
137138 private stop ( ) : void {
138- if ( this . _timeoutPromise ) {
139- this . _timeoutPromise . cancel ( ) ;
140- this . _timeoutPromise = null ;
139+ if ( this . _timeoutTimer ) {
140+ this . _timeoutTimer . cancel ( ) ;
141+ this . _timeoutTimer = null ;
141142 }
142143 if ( this . _computePromise ) {
143144 this . _computePromise . cancel ( ) ;
0 commit comments