Skip to content

Commit 2d51cea

Browse files
Tyriarbpasero
andauthored
Batch/defer history service navigation events (microsoft#163845)
* Batch/defer history service navigation events Part of microsoft#161622 * Pass store through Event.accumulate * Remove duplicate function * Action feedback * 💄 Co-authored-by: Benjamin Pasero <[email protected]> Co-authored-by: Benjamin Pasero <[email protected]>
1 parent 3444a91 commit 2d51cea

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

src/vs/base/common/event.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,6 @@ export namespace Event {
7070
return debounce<unknown, void>(event, () => void 0, 0, undefined, undefined, disposable);
7171
}
7272

73-
/**
74-
* Debounces an event, firing after some delay (default=0) with an array of all event original objects.
75-
*
76-
* *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
77-
* event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
78-
* returned event causes this utility to leak a listener on the original event.
79-
*/
80-
export function accumulate<T>(event: Event<T>, delay: number = 0, disposable?: DisposableStore): Event<T[]> {
81-
return Event.debounce<T, T[]>(event, (last, e) => {
82-
if (!last) {
83-
return [e];
84-
}
85-
last.push(e);
86-
return last;
87-
}, delay, undefined, undefined, disposable);
88-
}
89-
9073
/**
9174
* Given an event, returns another event which only fires once.
9275
*/
@@ -260,6 +243,23 @@ export namespace Event {
260243
return emitter.event;
261244
}
262245

246+
/**
247+
* Debounces an event, firing after some delay (default=0) with an array of all event original objects.
248+
*
249+
* *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
250+
* event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
251+
* returned event causes this utility to leak a listener on the original event.
252+
*/
253+
export function accumulate<T>(event: Event<T>, delay: number = 0, disposable?: DisposableStore): Event<T[]> {
254+
return Event.debounce<T, T[]>(event, (last, e) => {
255+
if (!last) {
256+
return [e];
257+
}
258+
last.push(e);
259+
return last;
260+
}, delay, undefined, undefined, disposable);
261+
}
262+
263263
/**
264264
* *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
265265
* event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the

src/vs/workbench/services/history/browser/historyService.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,12 @@ export class HistoryService extends Disposable implements IHistoryService {
160160
this.handleActiveEditorChange(activeEditorGroup, activeEditorPane);
161161

162162
// Listen to selection changes if the editor pane
163-
// is having a selection concept.
163+
// is having a selection concept. We use `accumulate`
164+
// on the event to reduce the pressure on the editor
165+
// to reduce input latency.
166+
164167
if (isEditorPaneWithSelection(activeEditorPane)) {
165-
this.activeEditorListeners.add(activeEditorPane.onDidChangeSelection(e => this.handleActiveEditorSelectionChangeEvent(activeEditorGroup, activeEditorPane, e)));
168+
this.activeEditorListeners.add(Event.accumulate(activeEditorPane.onDidChangeSelection)(e => this.handleActiveEditorSelectionChangeEvents(activeEditorGroup, activeEditorPane, e)));
166169
}
167170

168171
// Context keys
@@ -198,8 +201,10 @@ export class HistoryService extends Disposable implements IHistoryService {
198201
this.handleActiveEditorChangeInNavigationStacks(group, editorPane);
199202
}
200203

201-
private handleActiveEditorSelectionChangeEvent(group: IEditorGroup, editorPane: IEditorPaneWithSelection, event: IEditorPaneSelectionChangeEvent): void {
202-
this.handleActiveEditorSelectionChangeInNavigationStacks(group, editorPane, event);
204+
private handleActiveEditorSelectionChangeEvents(group: IEditorGroup, editorPane: IEditorPaneWithSelection, events: IEditorPaneSelectionChangeEvent[]): void {
205+
for (const event of events) {
206+
this.handleActiveEditorSelectionChangeInNavigationStacks(group, editorPane, event);
207+
}
203208
}
204209

205210
private move(event: FileOperationEvent): void {

0 commit comments

Comments
 (0)