diff --git a/src/CompositionHelper.test.ts b/src/CompositionHelper.test.ts index 053a0c29..156f5a44 100644 --- a/src/CompositionHelper.test.ts +++ b/src/CompositionHelper.test.ts @@ -6,6 +6,7 @@ import { assert } from 'chai'; import { CompositionHelper } from './CompositionHelper'; import { ITerminal } from './Types'; +import { MockCharSizeService } from 'TestUtils.test'; describe('CompositionHelper', () => { let terminal: ITerminal; @@ -48,16 +49,12 @@ describe('CompositionHelper', () => { buffer: { isCursorInViewport: true }, - charMeasure: { - height: 10, - width: 10 - }, options: { lineHeight: 1 } } as any; handledText = ''; - compositionHelper = new CompositionHelper(textarea, compositionView, terminal); + compositionHelper = new CompositionHelper(textarea, compositionView, terminal, new MockCharSizeService(10, 10)); }); describe('Input', () => { diff --git a/src/CompositionHelper.ts b/src/CompositionHelper.ts index 840bef55..e1179fed 100644 --- a/src/CompositionHelper.ts +++ b/src/CompositionHelper.ts @@ -4,6 +4,7 @@ */ import { ITerminal } from './Types'; +import { ICharSizeService } from 'ui/services/Services'; interface IPosition { start: number; @@ -42,7 +43,8 @@ export class CompositionHelper { constructor( private _textarea: HTMLTextAreaElement, private _compositionView: HTMLElement, - private _terminal: ITerminal + private _terminal: ITerminal, + private _charSizeService: ICharSizeService ) { this._isComposing = false; this._isSendingComposition = false; @@ -195,9 +197,9 @@ export class CompositionHelper { } if (this._terminal.buffer.isCursorInViewport) { - const cellHeight = Math.ceil(this._terminal.charMeasure.height * this._terminal.options.lineHeight); + const cellHeight = Math.ceil(this._charSizeService.height * this._terminal.options.lineHeight); const cursorTop = this._terminal.buffer.y * cellHeight; - const cursorLeft = this._terminal.buffer.x * this._terminal.charMeasure.width; + const cursorLeft = this._terminal.buffer.x * this._charSizeService.width; this._compositionView.style.left = cursorLeft + 'px'; this._compositionView.style.top = cursorTop + 'px'; diff --git a/src/MouseHelper.test.ts b/src/MouseHelper.test.ts index 7ca165e8..946b3cb8 100644 --- a/src/MouseHelper.test.ts +++ b/src/MouseHelper.test.ts @@ -22,12 +22,6 @@ describe('MouseHelper.getCoords', () => { mouseHelper = new MouseHelper(renderer as any, new MockCharSizeService(CHAR_WIDTH, CHAR_HEIGHT)); }); - describe('when charMeasure is not initialized', () => { - it('should return null', () => { - assert.equal(mouseHelper.getCoords({ clientX: 0, clientY: 0 }, document.createElement('div'), 10, 10), null); - }); - }); - it('should return the cell that was clicked', () => { let coords: [number, number]; coords = mouseHelper.getCoords({ clientX: CHAR_WIDTH / 2, clientY: CHAR_HEIGHT / 2 }, document.createElement('div'), 10, 10); diff --git a/src/MouseHelper.ts b/src/MouseHelper.ts index 091d00ae..d5662ab0 100644 --- a/src/MouseHelper.ts +++ b/src/MouseHelper.ts @@ -25,7 +25,6 @@ export class MouseHelper implements IMouseHelper { * little faster and this function is used in some low level code. * @param event The mouse event. * @param element The terminal's container element. - * @param charMeasure The char measure object used to determine character sizes. * @param colCount The number of columns in the terminal. * @param rowCount The number of rows n the terminal. * @param isSelection Whether the request is for the selection or not. This will @@ -61,7 +60,6 @@ export class MouseHelper implements IMouseHelper { * as expected by xterm. * @param event The mouse event. * @param element The terminal's container element. - * @param charMeasure The char measure object used to determine character sizes. * @param colCount The number of columns in the terminal. * @param rowCount The number of rows in the terminal. */ diff --git a/src/Terminal.ts b/src/Terminal.ts index f68d3105..1f010382 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -614,14 +614,14 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II this.register(addDisposableDomListener(this.textarea, 'blur', () => this._onTextAreaBlur())); this._helperContainer.appendChild(this.textarea); - this._compositionView = document.createElement('div'); - this._compositionView.classList.add('composition-view'); - this._compositionHelper = new CompositionHelper(this.textarea, this._compositionView, this); - this._helperContainer.appendChild(this._compositionView); - this.charMeasure = new CharMeasure(document, this._helperContainer); this._charSizeService = new CharSizeService(this._document, this._helperContainer, this.optionsService); + this._compositionView = document.createElement('div'); + this._compositionView.classList.add('composition-view'); + this._compositionHelper = new CompositionHelper(this.textarea, this._compositionView, this, this._charSizeService); + this._helperContainer.appendChild(this._compositionView); + // Performance: Add viewport and helper elements from the fragment this.element.appendChild(fragment);