From 30be7f138a7d0c00577b4d333ee2a5c87f0cb517 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Mon, 5 Sep 2016 11:47:13 +0200 Subject: [PATCH] Fixes Microsoft/monaco-editor#127: Set the font on the canvas context correctly, add an extra 2px for Japanese --- src/vs/editor/browser/controller/keyboardHandler.ts | 8 +++++--- src/vs/editor/common/controller/textAreaHandler.ts | 7 ++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/vs/editor/browser/controller/keyboardHandler.ts b/src/vs/editor/browser/controller/keyboardHandler.ts index 6341ee3386a..a8040a835af 100644 --- a/src/vs/editor/browser/controller/keyboardHandler.ts +++ b/src/vs/editor/browser/controller/keyboardHandler.ts @@ -109,12 +109,14 @@ export class KeyboardHandler extends ViewEventHandler implements IDisposable { let cs = dom.getComputedStyle(this.textArea.actual); if (browser.isFirefox) { // computedStyle.font is empty in Firefox... - context.font = `${cs.fontStyle} ${cs.fontVariant} ${cs.fontWeight} ${cs.fontStretch} ${cs.fontSize} / ${cs.lineHeight} '${cs.fontFamily}'`; + context.font = `${cs.fontStyle} ${cs.fontVariant} ${cs.fontWeight} ${cs.fontStretch} ${cs.fontSize} / ${cs.lineHeight} ${cs.fontFamily}`; + let metrics = context.measureText(e.data); + StyleMutator.setWidth(this.textArea.actual, metrics.width + 2); // +2 for Japanese... } else { context.font = cs.font; + let metrics = context.measureText(e.data); + StyleMutator.setWidth(this.textArea.actual, metrics.width); } - let metrics = context.measureText(e.data); - StyleMutator.setWidth(this.textArea.actual, metrics.width); } })); diff --git a/src/vs/editor/common/controller/textAreaHandler.ts b/src/vs/editor/common/controller/textAreaHandler.ts index ee8ad3804c0..90c7dcdb48f 100644 --- a/src/vs/editor/common/controller/textAreaHandler.ts +++ b/src/vs/editor/common/controller/textAreaHandler.ts @@ -117,11 +117,8 @@ export class TextAreaHandler extends Disposable { this.textareaIsShownAtCursor = true; // In IE we cannot set .value when handling 'compositionstart' because the entire composition will get canceled. - let shouldEmptyTextArea = true; - if (shouldEmptyTextArea) { - if (!this.Browser.isEdgeOrIE) { - this.setTextAreaState('compositionstart', this.textAreaState.toEmpty()); - } + if (!this.Browser.isEdgeOrIE) { + this.setTextAreaState('compositionstart', this.textAreaState.toEmpty()); } this._onCompositionStart.fire({