From ee1de0980f4923d3638b7355b3dc7ed32abf50ce Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 10 Feb 2017 09:55:35 -0800 Subject: [PATCH 1/2] Perform initial viewport sync after CharMeasure is ready Fixes #539 --- src/Viewport.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Viewport.ts b/src/Viewport.ts index aaafbc5f..dc7ff7c3 100644 --- a/src/Viewport.ts +++ b/src/Viewport.ts @@ -35,7 +35,8 @@ export class Viewport { this.terminal.on('resize', this.syncScrollArea.bind(this)); this.viewportElement.addEventListener('scroll', this.onScroll.bind(this)); - this.syncScrollArea(); + // Perform this async to ensure the CharMeasure is ready. + setTimeout(() => this.syncScrollArea(), 0); } /** From 92f27d3144df75654af39e7e90b640905eae0528 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Mon, 13 Feb 2017 09:48:22 -0800 Subject: [PATCH 2/2] Fix tests --- src/Viewport.test.ts | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/src/Viewport.test.ts b/src/Viewport.test.ts index 4fa77ec0..70ee97eb 100644 --- a/src/Viewport.test.ts +++ b/src/Viewport.test.ts @@ -41,13 +41,17 @@ describe('Viewport', () => { }); describe('refresh', () => { - it('should set the line-height of the terminal', () => { - assert.equal(viewportElement.style.lineHeight, CHARACTER_HEIGHT + 'px'); - assert.equal(terminal.rowContainer.style.lineHeight, CHARACTER_HEIGHT + 'px'); - charMeasure.height = 1; - viewport.refresh(); - assert.equal(viewportElement.style.lineHeight, '1px'); - assert.equal(terminal.rowContainer.style.lineHeight, '1px'); + it('should set the line-height of the terminal', done => { + // Allow CharMeasure to be initialized + setTimeout(() => { + assert.equal(viewportElement.style.lineHeight, CHARACTER_HEIGHT + 'px'); + assert.equal(terminal.rowContainer.style.lineHeight, CHARACTER_HEIGHT + 'px'); + charMeasure.height = 1; + viewport.refresh(); + assert.equal(viewportElement.style.lineHeight, '1px'); + assert.equal(terminal.rowContainer.style.lineHeight, '1px'); + done(); + }, 0); }); it('should set the height of the viewport when the line-height changed', () => { terminal.lines.push(''); @@ -62,17 +66,21 @@ describe('Viewport', () => { }); describe('syncScrollArea', () => { - it('should sync the scroll area', () => { - terminal.lines.push(''); - terminal.rows = 1; - assert.equal(scrollAreaElement.style.height, 0 * CHARACTER_HEIGHT + 'px'); - viewport.syncScrollArea(); - assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px'); - assert.equal(scrollAreaElement.style.height, 1 * CHARACTER_HEIGHT + 'px'); - terminal.lines.push(''); - viewport.syncScrollArea(); - assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px'); - assert.equal(scrollAreaElement.style.height, 2 * CHARACTER_HEIGHT + 'px'); + it('should sync the scroll area', done => { + // Allow CharMeasure to be initialized + setTimeout(() => { + terminal.lines.push(''); + terminal.rows = 1; + assert.equal(scrollAreaElement.style.height, 0 * CHARACTER_HEIGHT + 'px'); + viewport.syncScrollArea(); + assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px'); + assert.equal(scrollAreaElement.style.height, 1 * CHARACTER_HEIGHT + 'px'); + terminal.lines.push(''); + viewport.syncScrollArea(); + assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px'); + assert.equal(scrollAreaElement.style.height, 2 * CHARACTER_HEIGHT + 'px'); + done(); + }, 0); }); }); });