mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Make DebouncedIdleTask helper
This commit is contained in:
@@ -12,7 +12,7 @@ import { addDisposableDomListener } from 'browser/Lifecycle';
|
||||
import { IColorSet, IRenderDebouncerWithCallback } from 'browser/Types';
|
||||
import { IOptionsService, IBufferService, IDecorationService } from 'common/services/Services';
|
||||
import { ICharSizeService, ICoreBrowserService, IRenderService } from 'browser/services/Services';
|
||||
import { IdleTaskQueue } from 'common/IdleTaskQueue';
|
||||
import { DebouncedIdleTask } from 'common/Idle';
|
||||
|
||||
interface ISelectionState {
|
||||
start: [number, number] | undefined;
|
||||
@@ -106,7 +106,7 @@ export class RenderService extends Disposable implements IRenderService {
|
||||
}
|
||||
|
||||
if (!this._isPaused && this._needsFullRefresh) {
|
||||
this._pausedResizeQueue.flush();
|
||||
this._pausedResizeTask.flush();
|
||||
this.refreshRows(0, this._rowCount - 1);
|
||||
this._needsFullRefresh = false;
|
||||
}
|
||||
@@ -205,11 +205,10 @@ export class RenderService extends Disposable implements IRenderService {
|
||||
this.refreshRows(0, this._rowCount - 1);
|
||||
}
|
||||
|
||||
private _pausedResizeQueue = new IdleTaskQueue();
|
||||
private _pausedResizeTask = new DebouncedIdleTask();
|
||||
public onResize(cols: number, rows: number): void {
|
||||
if (this._isPaused) {
|
||||
this._pausedResizeQueue.clear();
|
||||
this._pausedResizeQueue.enqueue(() => this._renderer.onResize(cols, rows));
|
||||
this._pausedResizeTask.set(() => this._renderer.onResize(cols, rows));
|
||||
} else {
|
||||
this._renderer.onResize(cols, rows);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
* and care should be taken to ensure they're non-urgent and will not introduce race conditions.
|
||||
*/
|
||||
export class IdleTaskQueue {
|
||||
private _tasks: Function[] = [];
|
||||
private _tasks: (() => void)[] = [];
|
||||
private _idleCallback?: number;
|
||||
private _maxTaskDuration: number;
|
||||
private _i = 0;
|
||||
@@ -24,7 +24,7 @@ export class IdleTaskQueue {
|
||||
/**
|
||||
* Adds a task to the queue which will run in a future idle callback.
|
||||
*/
|
||||
public enqueue(task: Function): void {
|
||||
public enqueue(task: () => void): void {
|
||||
this._tasks.push(task);
|
||||
this._start();
|
||||
}
|
||||
@@ -70,3 +70,23 @@ export class IdleTaskQueue {
|
||||
this.clear();
|
||||
}
|
||||
}
|
||||
|
||||
export class DebouncedIdleTask {
|
||||
private _queue: IdleTaskQueue;
|
||||
|
||||
/**
|
||||
* @param targetFps The target frame rate.
|
||||
*/
|
||||
constructor(targetFps: number = 240) {
|
||||
this._queue = new IdleTaskQueue(targetFps);
|
||||
}
|
||||
|
||||
public set(task: () => void): void {
|
||||
this._queue.clear();
|
||||
this._queue.enqueue(task);
|
||||
}
|
||||
|
||||
public flush(): void {
|
||||
this._queue.flush();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user