Skip to content

Commit 07aacf8

Browse files
committed
Pass through _store
1 parent 58ac24e commit 07aacf8

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/vs/base/common/event.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,20 @@ export namespace Event {
5454
}
5555

5656
/**
57-
* Given an event, returns another event which debounces calls and defers the listeners to a
58-
* later task via a shared `setTimeout`. The event is converted into a signal (`Event<void>`) to
59-
* avoid additional object creation as a result of merging events and to try prevent race
60-
* conditions that could arise when using related deferred and non-deferred events.
57+
* Given an event, returns another event which debounces calls and defers the listeners to a later task via a shared
58+
* `setTimeout`. The event is converted into a signal (`Event<void>`) to avoid additional object creation as a
59+
* result of merging events and to try prevent race conditions that could arise when using related deferred and
60+
* non-deferred events.
6161
*
62-
* This is useful for deferring non-critical work (eg. general UI updates) to ensure it does not
63-
* block critical work (eg. latency of keypress to text rendered).
62+
* This is useful for deferring non-critical work (eg. general UI updates) to ensure it does not block critical work
63+
* (eg. latency of keypress to text rendered).
64+
*
65+
* *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
66+
* event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
67+
* returned event causes this utility to leak a listener on the original event.
6468
*/
65-
export function defer(event: Event<unknown>): Event<void> {
66-
return debounce<unknown, void>(event, () => void 0, 0);
69+
export function defer(event: Event<unknown>, disposable?: DisposableStore): Event<void> {
70+
return debounce<unknown, void>(event, () => void 0, 0, undefined, undefined, disposable);
6771
}
6872

6973
/**

src/vs/editor/browser/widget/codeEditorWidget.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
148148

149149
private readonly _onDidChangeCursorPosition: Emitter<ICursorPositionChangedEvent> = this._register(new Emitter<ICursorPositionChangedEvent>({ deliveryQueue: this._deliveryQueue }));
150150
public readonly onDidChangeCursorPosition: Event<ICursorPositionChangedEvent> = this._onDidChangeCursorPosition.event;
151-
public readonly onDidChangeCursorPositionDeferred: Event<void> = Event.defer(this._onDidChangeCursorPosition.event);
151+
public readonly onDidChangeCursorPositionDeferred: Event<void> = Event.defer(this._onDidChangeCursorPosition.event, this._store);
152152

153153
private readonly _onDidChangeCursorSelection: Emitter<ICursorSelectionChangedEvent> = this._register(new Emitter<ICursorSelectionChangedEvent>({ deliveryQueue: this._deliveryQueue }));
154154
public readonly onDidChangeCursorSelection: Event<ICursorSelectionChangedEvent> = this._onDidChangeCursorSelection.event;

src/vs/workbench/browser/parts/editor/editorStatus.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,6 @@ export class EditorStatus extends Disposable implements IWorkbenchContribution {
673673

674674
// Hook Listener for Selection changes
675675
this.activeEditorListeners.add(activeCodeEditor.onDidChangeCursorPositionDeferred(() => {
676-
console.log('cursor position change');
677676
this.onSelectionChange(activeCodeEditor);
678677
this.currentProblemStatus.update(activeCodeEditor);
679678
}));

0 commit comments

Comments
 (0)