Fire only once per item (fixes #46669 and #46671)

This commit is contained in:
Christof Marti 2018-03-28 15:01:49 +02:00
parent dfec7a4789
commit 4b95443bff
3 changed files with 15 additions and 5 deletions

View file

@ -365,6 +365,7 @@ export interface IChainableEvent<T> {
map<O>(fn: (i: T) => O): IChainableEvent<O>;
forEach(fn: (i: T) => void): IChainableEvent<T>;
filter(fn: (e: T) => boolean): IChainableEvent<T>;
latch(): IChainableEvent<T>;
on(listener: (e: T) => any, thisArgs?: any, disposables?: IDisposable[]): IDisposable;
}
@ -398,6 +399,10 @@ class ChainableEvent<T> implements IChainableEvent<T> {
return new ChainableEvent(filterEvent(this._event, fn));
}
latch(): IChainableEvent<T> {
return new ChainableEvent(latch(this._event));
}
on(listener: (e: T) => any, thisArgs: any, disposables: IDisposable[]) {
return this._event(listener, thisArgs, disposables);
}

View file

@ -29,6 +29,7 @@ import { CountBadge } from 'vs/base/browser/ui/countBadge/countBadge';
import { attachBadgeStyler, attachProgressBarStyler } from 'vs/platform/theme/common/styler';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { ProgressBar } from 'vs/base/browser/ui/progressbar/progressbar';
import { chain } from 'vs/base/common/event';
const $ = dom.$;
@ -127,11 +128,13 @@ export class QuickInputService extends Component implements IQuickInputService {
this.inputBox.setFocus();
}, 0);
}));
this.toUnbind.push(this.checkboxList.onFocusChange(e => {
if (this.progress && e.length) {
this.progress(e[0]);
}
}));
this.toUnbind.push(
chain(this.checkboxList.onFocusChange)
.map(e => e[0])
.filter(e => !!e)
.latch()
.on(e => this.progress && this.progress(e))
);
this.toUnbind.push(dom.addDisposableListener(this.container, 'focusout', (e: FocusEvent) => {
for (let element = <Element>e.relatedTarget; element; element = element.parentElement) {

View file

@ -21,6 +21,7 @@ import { KeyCode } from 'vs/base/common/keyCodes';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { IconLabel, IIconLabelValueOptions } from 'vs/base/browser/ui/iconLabel/iconLabel';
import { HighlightedLabel } from 'vs/base/browser/ui/highlightedlabel/highlightedLabel';
import { memoize } from 'vs/base/common/decorators';
const $ = dom.$;
@ -181,6 +182,7 @@ export class QuickInputCheckboxList {
}));
}
@memoize
get onFocusChange() {
return mapEvent(this.list.onFocusChange, e => e.elements.map(e => e.item));
}