Skip to content

Commit

Permalink
Merge pull request #463 from sourcelair/revert-445-444_rate_limit_vie…
Browse files Browse the repository at this point in the history
…wport_refresh

Revert "Rate limit Viewport.refresh"
  • Loading branch information
Tyriar committed Jan 9, 2017
2 parents eb3b3fa + 06852cd commit facc265
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 27 deletions.
10 changes: 0 additions & 10 deletions src/Viewport.test.ts
@@ -1,11 +1,6 @@
import { assert } from 'chai';
import { Viewport } from './Viewport';

class MockWindow {
// Disable refreshLoop in test
public requestAnimationFrame() { }
}

describe('Viewport', () => {
var terminal;
var viewportElement;
Expand All @@ -16,7 +11,6 @@ describe('Viewport', () => {
const CHARACTER_HEIGHT = 10;

beforeEach(() => {
(<any>global).window = new MockWindow();
terminal = {
lines: [],
rows: 0,
Expand Down Expand Up @@ -79,14 +73,10 @@ describe('Viewport', () => {
terminal.rows = 1;
assert.equal(scrollAreaElement.style.height, 0 * CHARACTER_HEIGHT + 'px');
viewport.syncScrollArea();
assert.ok(viewport.isRefreshQueued);
viewport.refresh();
assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
assert.equal(scrollAreaElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
terminal.lines.push('');
viewport.syncScrollArea();
assert.ok(viewport.isRefreshQueued);
viewport.refresh();
assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
assert.equal(scrollAreaElement.style.height, 2 * CHARACTER_HEIGHT + 'px');
});
Expand Down
20 changes: 3 additions & 17 deletions src/Viewport.ts
Expand Up @@ -12,7 +12,6 @@ export class Viewport {
private currentRowHeight: number;
private lastRecordedBufferLength: number;
private lastRecordedViewportHeight: number;
private isRefreshQueued: boolean;

/**
* Creates a new Viewport.
Expand All @@ -30,25 +29,12 @@ export class Viewport {
this.currentRowHeight = 0;
this.lastRecordedBufferLength = 0;
this.lastRecordedViewportHeight = 0;
this.isRefreshQueued = false;

this.terminal.on('scroll', this.syncScrollArea.bind(this));
this.terminal.on('resize', this.syncScrollArea.bind(this));
this.viewportElement.addEventListener('scroll', this.onScroll.bind(this));

this.syncScrollArea();
this.refreshLoop();
}

/**
* Queues a refresh to be done on next animation frame.
*/
private refreshLoop(): void {
if (this.isRefreshQueued) {
this.refresh();
this.isRefreshQueued = false;
}
window.requestAnimationFrame(this.refreshLoop.bind(this));
}

/**
Expand Down Expand Up @@ -82,15 +68,15 @@ export class Viewport {
if (this.lastRecordedBufferLength !== this.terminal.lines.length) {
// If buffer height changed
this.lastRecordedBufferLength = this.terminal.lines.length;
this.isRefreshQueued = true;
this.refresh();
} else if (this.lastRecordedViewportHeight !== this.terminal.rows) {
// If viewport height changed
this.isRefreshQueued = true;
this.refresh();
} else {
// If size has changed, refresh viewport
var size = this.charMeasureElement.getBoundingClientRect();
if (size.height !== this.currentRowHeight) {
this.isRefreshQueued = true;
this.refresh(size);
}
}

Expand Down

0 comments on commit facc265

Please sign in to comment.