mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-21 22:34:31 +01:00
don't fire context key change async
This commit is contained in:
@@ -31,16 +31,16 @@ export class Menu implements IMenu {
|
||||
debounceEvent(
|
||||
filterEvent(MenuRegistry.onDidChangeMenu, menuId => menuId === this._id),
|
||||
() => { },
|
||||
100
|
||||
50
|
||||
)(this._build, this, this._disposables);
|
||||
|
||||
// when context keys change we need to change if the menu also
|
||||
// when context keys change we need to check if the menu also
|
||||
// has changed
|
||||
this._contextKeyService.onDidChangeContext(event => {
|
||||
if (event.affectsSome(this._contextKeys)) {
|
||||
this._onDidChange.fire();
|
||||
}
|
||||
}, this, this._disposables);
|
||||
debounceEvent(
|
||||
this._contextKeyService.onDidChangeContext,
|
||||
(last, event) => last || event.affectsSome(this._contextKeys),
|
||||
50
|
||||
)(e => e && this._onDidChange.fire(), this, this._disposables);
|
||||
}
|
||||
|
||||
private _build(): void {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Emitter, Event, debounceEvent } from 'vs/base/common/event';
|
||||
import { Emitter, Event, mapEvent } from 'vs/base/common/event';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { keys } from 'vs/base/common/map';
|
||||
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
|
||||
@@ -193,14 +193,14 @@ class ContextKey<T> implements IContextKey<T> {
|
||||
}
|
||||
}
|
||||
|
||||
export class ContextKeyChangeEvent implements IContextKeyChangeEvent {
|
||||
|
||||
private _keys: string[] = [];
|
||||
|
||||
collect(oneOrManyKeys: string | string[]): void {
|
||||
this._keys = this._keys.concat(oneOrManyKeys);
|
||||
class SimpleContextKeyChangeEvent implements IContextKeyChangeEvent {
|
||||
constructor(private readonly _key: string) { }
|
||||
affectsSome(keys: IReadableSet<string>): boolean {
|
||||
return keys.has(this._key);
|
||||
}
|
||||
|
||||
}
|
||||
class ArrayContextKeyChangeEvent implements IContextKeyChangeEvent {
|
||||
constructor(private readonly _keys: string[]) { }
|
||||
affectsSome(keys: IReadableSet<string>): boolean {
|
||||
for (const key of this._keys) {
|
||||
if (keys.has(key)) {
|
||||
@@ -236,13 +236,11 @@ export abstract class AbstractContextKeyService implements IContextKeyService {
|
||||
|
||||
public get onDidChangeContext(): Event<IContextKeyChangeEvent> {
|
||||
if (!this._onDidChangeContext) {
|
||||
this._onDidChangeContext = debounceEvent<string | string[], ContextKeyChangeEvent>(this._onDidChangeContextKey.event, (prev, cur) => {
|
||||
if (!prev) {
|
||||
prev = new ContextKeyChangeEvent();
|
||||
}
|
||||
prev.collect(cur);
|
||||
return prev;
|
||||
}, 25);
|
||||
this._onDidChangeContext = mapEvent(this._onDidChangeContextKey.event, ((changedKeyOrKeys): IContextKeyChangeEvent => {
|
||||
return typeof changedKeyOrKeys === 'string'
|
||||
? new SimpleContextKeyChangeEvent(changedKeyOrKeys)
|
||||
: new ArrayContextKeyChangeEvent(changedKeyOrKeys);
|
||||
}));
|
||||
}
|
||||
return this._onDidChangeContext;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user