Merge pull request #2303 from Tyriar/compositionhelper_browser

Move CompositionHelper into browser
This commit is contained in:
Daniel Imms
2019-07-13 00:30:27 -07:00
committed by GitHub
4 changed files with 17 additions and 37 deletions
+2 -2
View File
@@ -23,7 +23,7 @@
import { IInputHandlingTerminal, IViewport, ICompositionHelper, ITerminalOptions, ITerminal, IBrowser, ILinkifier, ILinkMatcherOptions, CustomKeyEventHandler, LinkMatcherHandler, IMouseZoneManager } from './Types';
import { IRenderer, CharacterJoinerHandler } from 'browser/renderer/Types';
import { CompositionHelper } from './CompositionHelper';
import { CompositionHelper } from 'browser/input/CompositionHelper';
import { Viewport } from './Viewport';
import { rightClickHandler, moveTextAreaUnderMouseCursor, pasteHandler, copyHandler } from './Clipboard';
import { C0 } from 'common/data/EscapeSequences';
@@ -581,7 +581,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
this._compositionView = document.createElement('div');
this._compositionView.classList.add('composition-view');
this._compositionHelper = new CompositionHelper(this.textarea, this._compositionView, this, this._charSizeService, this._coreService);
this._compositionHelper = new CompositionHelper(this.textarea, this._compositionView, this._bufferService, this.optionsService, this._charSizeService, this._coreService);
this._helperContainer.appendChild(this._compositionView);
// Performance: Add viewport and helper elements from the fragment
@@ -4,13 +4,11 @@
*/
import { assert } from 'chai';
import { CompositionHelper } from './CompositionHelper';
import { ITerminal } from './Types';
import { CompositionHelper } from 'browser/input/CompositionHelper';
import { MockCharSizeService } from 'browser/TestUtils.test';
import { MockCoreService } from '../out/common/TestUtils.test';
import { MockCoreService, MockBufferService, MockOptionsService } from 'common/TestUtils.test';
describe('CompositionHelper', () => {
let terminal: ITerminal;
let compositionHelper: CompositionHelper;
let compositionView: HTMLElement;
let textarea: HTMLTextAreaElement;
@@ -38,25 +36,13 @@ describe('CompositionHelper', () => {
top: 0
}
} as any;
terminal = {
element: {
querySelector: () => {
return { offsetLeft: 0, offsetTop: 0 };
}
},
buffer: {
isCursorInViewport: true
},
options: {
lineHeight: 1
}
} as any;
const coreService = new MockCoreService();
coreService.triggerDataEvent = (text: string) => {
handledText += text;
};
handledText = '';
compositionHelper = new CompositionHelper(textarea, compositionView, terminal, new MockCharSizeService(10, 10), coreService);
const bufferService = new MockBufferService(10, 5);
compositionHelper = new CompositionHelper(textarea, compositionView, bufferService, new MockOptionsService(), new MockCharSizeService(10, 10), coreService);
});
describe('Input', () => {
@@ -3,9 +3,8 @@
* @license MIT
*/
import { ITerminal } from './Types';
import { ICharSizeService } from 'browser/services/Services';
import { ICoreService } from 'common/services/Services';
import { IBufferService, ICoreService, IOptionsService } from 'common/services/Services';
interface IPosition {
start: number;
@@ -35,22 +34,17 @@ export class CompositionHelper {
*/
private _isSendingComposition: boolean;
/**
* Creates a new CompositionHelper.
* @param _textarea The textarea that xterm uses for input.
* @param _compositionView The element to display the in-progress composition in.
* @param _terminal The Terminal to forward the finished composition to.
*/
constructor(
private readonly _textarea: HTMLTextAreaElement,
private readonly _compositionView: HTMLElement,
private readonly _terminal: ITerminal,
private readonly _bufferService: IBufferService,
private readonly _optionsService: IOptionsService,
private readonly _charSizeService: ICharSizeService,
private readonly _coreService: ICoreService
) {
this._isComposing = false;
this._isSendingComposition = false;
this._compositionPosition = { start: null, end: null };
this._compositionPosition = { start: 0, end: 0 };
}
/**
@@ -198,17 +192,17 @@ export class CompositionHelper {
return;
}
if (this._terminal.buffer.isCursorInViewport) {
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._charSizeService.width;
if (this._bufferService.buffer.isCursorInViewport) {
const cellHeight = Math.ceil(this._charSizeService.height * this._optionsService.options.lineHeight);
const cursorTop = this._bufferService.buffer.y * cellHeight;
const cursorLeft = this._bufferService.buffer.x * this._charSizeService.width;
this._compositionView.style.left = cursorLeft + 'px';
this._compositionView.style.top = cursorTop + 'px';
this._compositionView.style.height = cellHeight + 'px';
this._compositionView.style.lineHeight = cellHeight + 'px';
this._compositionView.style.fontFamily = this._terminal.options.fontFamily;
this._compositionView.style.fontSize = this._terminal.options.fontSize + 'px';
this._compositionView.style.fontFamily = this._optionsService.options.fontFamily;
this._compositionView.style.fontSize = this._optionsService.options.fontSize + 'px';
// Sync the textarea to the exact position of the composition view so the IME knows where the
// text is.
const compositionViewBounds = this._compositionView.getBoundingClientRect();
@@ -13,7 +13,7 @@ import { IBufferService, IOptionsService } from 'common/services/Services';
import { MockCharSizeService, MockMouseService } from 'browser/TestUtils.test';
import { CellData } from 'common/buffer/CellData';
import { IBuffer } from 'common/buffer/Types';
import { isWindows } from '../../../out/common/Platform';
import { isWindows } from 'common/Platform';
class TestSelectionService extends SelectionService {
constructor(