|
3 | 3 | * Licensed under the MIT License. See License.txt in the project root for license information. |
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
6 | | -import { Emitter, Event, debounceEvent } from 'vs/base/common/event'; |
| 6 | +import { Emitter, Event, mapEvent } from 'vs/base/common/event'; |
7 | 7 | import { IDisposable, dispose } from 'vs/base/common/lifecycle'; |
8 | 8 | import { keys } from 'vs/base/common/map'; |
9 | 9 | import { CommandsRegistry } from 'vs/platform/commands/common/commands'; |
@@ -193,14 +193,14 @@ class ContextKey<T> implements IContextKey<T> { |
193 | 193 | } |
194 | 194 | } |
195 | 195 |
|
196 | | -export class ContextKeyChangeEvent implements IContextKeyChangeEvent { |
197 | | - |
198 | | - private _keys: string[] = []; |
199 | | - |
200 | | - collect(oneOrManyKeys: string | string[]): void { |
201 | | - this._keys = this._keys.concat(oneOrManyKeys); |
| 196 | +class SimpleContextKeyChangeEvent implements IContextKeyChangeEvent { |
| 197 | + constructor(private readonly _key: string) { } |
| 198 | + affectsSome(keys: IReadableSet<string>): boolean { |
| 199 | + return keys.has(this._key); |
202 | 200 | } |
203 | | - |
| 201 | +} |
| 202 | +class ArrayContextKeyChangeEvent implements IContextKeyChangeEvent { |
| 203 | + constructor(private readonly _keys: string[]) { } |
204 | 204 | affectsSome(keys: IReadableSet<string>): boolean { |
205 | 205 | for (const key of this._keys) { |
206 | 206 | if (keys.has(key)) { |
@@ -236,13 +236,11 @@ export abstract class AbstractContextKeyService implements IContextKeyService { |
236 | 236 |
|
237 | 237 | public get onDidChangeContext(): Event<IContextKeyChangeEvent> { |
238 | 238 | if (!this._onDidChangeContext) { |
239 | | - this._onDidChangeContext = debounceEvent<string | string[], ContextKeyChangeEvent>(this._onDidChangeContextKey.event, (prev, cur) => { |
240 | | - if (!prev) { |
241 | | - prev = new ContextKeyChangeEvent(); |
242 | | - } |
243 | | - prev.collect(cur); |
244 | | - return prev; |
245 | | - }, 25); |
| 239 | + this._onDidChangeContext = mapEvent(this._onDidChangeContextKey.event, ((changedKeyOrKeys): IContextKeyChangeEvent => { |
| 240 | + return typeof changedKeyOrKeys === 'string' |
| 241 | + ? new SimpleContextKeyChangeEvent(changedKeyOrKeys) |
| 242 | + : new ArrayContextKeyChangeEvent(changedKeyOrKeys); |
| 243 | + })); |
246 | 244 | } |
247 | 245 | return this._onDidChangeContext; |
248 | 246 | } |
|
0 commit comments