From 13c401cbaa6719d6468ad7ae5ec18635d09bc0e1 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Tue, 6 Jun 2017 10:52:42 -0700 Subject: [PATCH] Only refresh the selection on an animation frame --- src/SelectionManager.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/SelectionManager.ts b/src/SelectionManager.ts index e026018a0..6dc34c655 100644 --- a/src/SelectionManager.ts +++ b/src/SelectionManager.ts @@ -79,6 +79,8 @@ export class SelectionManager extends EventEmitter { */ private _dragScrollIntervalTimer: NodeJS.Timer; + private _refreshAnimationFrame: number; + private _bufferTrimListener: any; private _mouseMoveListener: EventListener; private _mouseDownListener: EventListener; @@ -212,9 +214,20 @@ export class SelectionManager extends EventEmitter { } /** - * Redraws the selection. + * Queues a refresh, redrawing the selection on the next opportunity. */ public refresh(): void { + if (!this._refreshAnimationFrame) { + this._refreshAnimationFrame = window.requestAnimationFrame(() => this._refresh()); + } + } + + /** + * Fires the refresh event, causing consumers to pick it up and redraw the + * selection state. + */ + private _refresh(): void { + this._refreshAnimationFrame = null; this.emit('refresh', { start: this._model.finalSelectionStart, end: this._model.finalSelectionEnd }); }