Fixes Microsoft/monaco-editor#127: Set the font on the canvas context correctly, add an extra 2px for Japanese

This commit is contained in:
Alex Dima
2016-09-05 11:47:13 +02:00
parent 9fa56d6f7e
commit 30be7f138a
2 changed files with 7 additions and 8 deletions
@@ -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);
}
}));
@@ -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({