Use RenderService.dimensions instead of CharSizeService for textarea position
This commit is contained in:
+18
-14
@@ -297,19 +297,23 @@ export class Terminal extends CoreTerminal implements ITerminal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _syncTextArea(): void {
|
private _syncTextArea(): void {
|
||||||
if (!this.textarea || !this.buffer.isCursorInViewport || this._compositionHelper!.isComposing) {
|
if (!this.textarea || !this.buffer.isCursorInViewport || this._compositionHelper!.isComposing || !this._renderService) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const cursorY = this.buffer.ybase + this.buffer.y;
|
||||||
const cellHeight = Math.ceil(this._charSizeService!.height * this.optionsService.options.lineHeight);
|
const viewportRelativeCursorY = cursorY - this.buffer.ydisp;
|
||||||
const cursorTop = this._bufferService.buffer.y * cellHeight;
|
const cursorX = Math.min(this.buffer.x, this.cols - 1);
|
||||||
const cursorLeft = this._bufferService.buffer.x * this._charSizeService!.width;
|
const cellHeight = this._renderService.dimensions.actualCellHeight;
|
||||||
|
const width = this.buffer.lines.get(cursorY)!.getWidth(cursorX);
|
||||||
|
const cellWidth = this._renderService.dimensions.actualCellWidth * width;
|
||||||
|
const cursorTop = viewportRelativeCursorY * this._renderService.dimensions.actualCellHeight;
|
||||||
|
const cursorLeft = cursorX * this._renderService.dimensions.actualCellWidth;
|
||||||
|
|
||||||
// Sync the textarea to the exact position of the composition view so the IME knows where the
|
// Sync the textarea to the exact position of the composition view so the IME knows where the
|
||||||
// text is.
|
// text is.
|
||||||
this.textarea.style.left = cursorLeft + 'px';
|
this.textarea.style.left = cursorLeft + 'px';
|
||||||
this.textarea.style.top = cursorTop + 'px';
|
this.textarea.style.top = cursorTop + 'px';
|
||||||
this.textarea.style.width = this._charSizeService!.width + 'px';
|
this.textarea.style.width = cellWidth +'px';
|
||||||
this.textarea.style.height = cellHeight + 'px';
|
this.textarea.style.height = cellHeight + 'px';
|
||||||
this.textarea.style.lineHeight = cellHeight + 'px';
|
this.textarea.style.lineHeight = cellHeight + 'px';
|
||||||
this.textarea.style.zIndex = '-5';
|
this.textarea.style.zIndex = '-5';
|
||||||
@@ -438,14 +442,6 @@ export class Terminal extends CoreTerminal implements ITerminal {
|
|||||||
this._charSizeService = this._instantiationService.createInstance(CharSizeService, this._document, this._helperContainer);
|
this._charSizeService = this._instantiationService.createInstance(CharSizeService, this._document, this._helperContainer);
|
||||||
this._instantiationService.setService(ICharSizeService, this._charSizeService);
|
this._instantiationService.setService(ICharSizeService, this._charSizeService);
|
||||||
|
|
||||||
this._compositionView = document.createElement('div');
|
|
||||||
this._compositionView.classList.add('composition-view');
|
|
||||||
this._compositionHelper = this._instantiationService.createInstance(CompositionHelper, this.textarea, this._compositionView);
|
|
||||||
this._helperContainer.appendChild(this._compositionView);
|
|
||||||
|
|
||||||
// Performance: Add viewport and helper elements from the fragment
|
|
||||||
this.element.appendChild(fragment);
|
|
||||||
|
|
||||||
this._theme = this.options.theme || this._theme;
|
this._theme = this.options.theme || this._theme;
|
||||||
this._colorManager = new ColorManager(document, this.options.allowTransparency);
|
this._colorManager = new ColorManager(document, this.options.allowTransparency);
|
||||||
this.register(this.optionsService.onOptionChange(e => this._colorManager!.onOptionsChange(e)));
|
this.register(this.optionsService.onOptionChange(e => this._colorManager!.onOptionsChange(e)));
|
||||||
@@ -457,6 +453,14 @@ export class Terminal extends CoreTerminal implements ITerminal {
|
|||||||
this.register(this._renderService.onRenderedBufferChange(e => this._onRender.fire(e)));
|
this.register(this._renderService.onRenderedBufferChange(e => this._onRender.fire(e)));
|
||||||
this.onResize(e => this._renderService!.resize(e.cols, e.rows));
|
this.onResize(e => this._renderService!.resize(e.cols, e.rows));
|
||||||
|
|
||||||
|
this._compositionView = document.createElement('div');
|
||||||
|
this._compositionView.classList.add('composition-view');
|
||||||
|
this._compositionHelper = this._instantiationService.createInstance(CompositionHelper, this.textarea, this._compositionView);
|
||||||
|
this._helperContainer.appendChild(this._compositionView);
|
||||||
|
|
||||||
|
// Performance: Add viewport and helper elements from the fragment
|
||||||
|
this.element.appendChild(fragment);
|
||||||
|
|
||||||
this._soundService = this._instantiationService.createInstance(SoundService);
|
this._soundService = this._instantiationService.createInstance(SoundService);
|
||||||
this._instantiationService.setService(ISoundService, this._soundService);
|
this._instantiationService.setService(ISoundService, this._soundService);
|
||||||
this._mouseService = this._instantiationService.createInstance(MouseService);
|
this._mouseService = this._instantiationService.createInstance(MouseService);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import { assert } from 'chai';
|
import { assert } from 'chai';
|
||||||
import { CompositionHelper } from 'browser/input/CompositionHelper';
|
import { CompositionHelper } from 'browser/input/CompositionHelper';
|
||||||
import { MockCharSizeService } from 'browser/TestUtils.test';
|
import { MockCharSizeService, MockRenderService } from 'browser/TestUtils.test';
|
||||||
import { MockCoreService, MockBufferService, MockOptionsService } from 'common/TestUtils.test';
|
import { MockCoreService, MockBufferService, MockOptionsService } from 'common/TestUtils.test';
|
||||||
|
|
||||||
describe('CompositionHelper', () => {
|
describe('CompositionHelper', () => {
|
||||||
@@ -42,7 +42,7 @@ describe('CompositionHelper', () => {
|
|||||||
};
|
};
|
||||||
handledText = '';
|
handledText = '';
|
||||||
const bufferService = new MockBufferService(10, 5);
|
const bufferService = new MockBufferService(10, 5);
|
||||||
compositionHelper = new CompositionHelper(textarea, compositionView, bufferService, new MockOptionsService(), new MockCharSizeService(10, 10), coreService);
|
compositionHelper = new CompositionHelper(textarea, compositionView, bufferService, new MockOptionsService(), new MockCharSizeService(10, 10), coreService, new MockRenderService());
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Input', () => {
|
describe('Input', () => {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ICharSizeService } from 'browser/services/Services';
|
import { ICharSizeService, IRenderService } from 'browser/services/Services';
|
||||||
import { IBufferService, ICoreService, IOptionsService } from 'common/services/Services';
|
import { IBufferService, ICoreService, IOptionsService } from 'common/services/Services';
|
||||||
|
|
||||||
interface IPosition {
|
interface IPosition {
|
||||||
@@ -46,7 +46,8 @@ export class CompositionHelper {
|
|||||||
@IBufferService private readonly _bufferService: IBufferService,
|
@IBufferService private readonly _bufferService: IBufferService,
|
||||||
@IOptionsService private readonly _optionsService: IOptionsService,
|
@IOptionsService private readonly _optionsService: IOptionsService,
|
||||||
@ICharSizeService private readonly _charSizeService: ICharSizeService,
|
@ICharSizeService private readonly _charSizeService: ICharSizeService,
|
||||||
@ICoreService private readonly _coreService: ICoreService
|
@ICoreService private readonly _coreService: ICoreService,
|
||||||
|
@IRenderService private readonly _renderService: IRenderService
|
||||||
) {
|
) {
|
||||||
this._isComposing = false;
|
this._isComposing = false;
|
||||||
this._isSendingComposition = false;
|
this._isSendingComposition = false;
|
||||||
@@ -202,14 +203,18 @@ export class CompositionHelper {
|
|||||||
* necessary as the IME events across browsers are not consistently triggered.
|
* necessary as the IME events across browsers are not consistently triggered.
|
||||||
*/
|
*/
|
||||||
public updateCompositionElements(dontRecurse?: boolean): void {
|
public updateCompositionElements(dontRecurse?: boolean): void {
|
||||||
if (!this._isComposing) {
|
if (!this._isComposing || !this._renderService) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._bufferService.buffer.isCursorInViewport) {
|
if (this._bufferService.buffer.isCursorInViewport) {
|
||||||
const cellHeight = Math.ceil(this._charSizeService.height * this._optionsService.options.lineHeight);
|
const cursorY = this._bufferService.buffer.ybase + this._bufferService.buffer.y;
|
||||||
const cursorTop = this._bufferService.buffer.y * cellHeight;
|
const viewportRelativeCursorY = cursorY - this._bufferService.buffer.ydisp;
|
||||||
const cursorLeft = this._bufferService.buffer.x * this._charSizeService.width;
|
const cursorX = Math.min(this._bufferService.buffer.x, this._bufferService.cols - 1);
|
||||||
|
|
||||||
|
const cellHeight = this._renderService.dimensions.actualCellHeight;
|
||||||
|
const cursorTop = viewportRelativeCursorY * this._renderService.dimensions.actualCellHeight;
|
||||||
|
const cursorLeft = cursorX * this._renderService.dimensions.actualCellWidth;
|
||||||
|
|
||||||
this._compositionView.style.left = cursorLeft + 'px';
|
this._compositionView.style.left = cursorLeft + 'px';
|
||||||
this._compositionView.style.top = cursorTop + 'px';
|
this._compositionView.style.top = cursorTop + 'px';
|
||||||
|
|||||||
Reference in New Issue
Block a user