textAreaHandler.ts 19.8 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

6
import 'vs/css!./textAreaHandler';
7
import * as nls from 'vs/nls';
A
Alex Dima 已提交
8
import * as browser from 'vs/base/browser/browser';
A
Alex Dima 已提交
9 10 11
import { FastDomNode, createFastDomNode } from 'vs/base/browser/fastDomNode';
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import * as platform from 'vs/base/common/platform';
12
import * as strings from 'vs/base/common/strings';
J
Johannes Rieken 已提交
13
import { Configuration } from 'vs/editor/browser/config/configuration';
14
import { CopyOptions, ICompositionData, IPasteData, ITextAreaInputHost, TextAreaInput, ClipboardDataToCopy } from 'vs/editor/browser/controller/textAreaInput';
A
Alex Dima 已提交
15
import { ISimpleModel, ITypeData, PagedScreenReaderStrategy, TextAreaState } from 'vs/editor/browser/controller/textAreaState';
16
import { ViewController } from 'vs/editor/browser/view/viewController';
A
Alex Dima 已提交
17
import { PartFingerprint, PartFingerprints, ViewPart } from 'vs/editor/browser/view/viewPart';
18
import { LineNumbersOverlay } from 'vs/editor/browser/viewParts/lineNumbers/lineNumbers';
A
Alex Dima 已提交
19
import { Margin } from 'vs/editor/browser/viewParts/margin/margin';
20
import { RenderLineNumbersType, EditorOption, IComputedEditorOptions } from 'vs/editor/common/config/editorOptions';
A
Alex Dima 已提交
21 22 23 24 25 26
import { BareFontInfo } from 'vs/editor/common/config/fontInfo';
import { WordCharacterClass, getMapForWordSeparators } from 'vs/editor/common/controller/wordCharacterClassifier';
import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection';
import { ScrollType } from 'vs/editor/common/editorCommon';
A
Alex Dima 已提交
27
import { EndOfLinePreference } from 'vs/editor/common/model';
A
Alex Dima 已提交
28 29 30
import { HorizontalRange, RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/view/renderingContext';
import { ViewContext } from 'vs/editor/common/view/viewContext';
import * as viewEvents from 'vs/editor/common/view/viewEvents';
31
import { AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility';
32

33
export interface ITextAreaHandlerHelper {
A
Alex Dima 已提交
34
	visibleRangeForPositionRelativeToEditor(lineNumber: number, column: number): HorizontalRange | null;
35
}
36

37
class VisibleTextAreaData {
38
	_visibleTextAreaBrand: void;
39 40 41

	public readonly top: number;
	public readonly left: number;
42
	public readonly width: number;
43

44
	constructor(top: number, left: number, width: number) {
45 46
		this.top = top;
		this.left = left;
47 48 49
		this.width = width;
	}

50 51
	public setWidth(width: number): VisibleTextAreaData {
		return new VisibleTextAreaData(this.top, this.left, width);
52 53
	}
}
54

55 56 57
const canUseZeroSizeTextarea = (browser.isEdgeOrIE || browser.isFirefox);

export class TextAreaHandler extends ViewPart {
58

59
	private readonly _viewController: ViewController;
60
	private readonly _viewHelper: ITextAreaHandlerHelper;
A
Alex Dima 已提交
61 62 63
	private _scrollLeft: number;
	private _scrollTop: number;

64
	private _accessibilitySupport: AccessibilitySupport;
65 66
	private _contentLeft: number;
	private _contentWidth: number;
67
	private _contentHeight: number;
68 69
	private _fontInfo: BareFontInfo;
	private _lineHeight: number;
70
	private _emptySelectionClipboard: boolean;
71
	private _copyWithSyntaxHighlighting: boolean;
72 73 74 75

	/**
	 * Defined only when the text area is visible (composition case).
	 */
A
Alex Dima 已提交
76
	private _visibleTextArea: VisibleTextAreaData | null;
77
	private _selections: Selection[];
A
Alex Dima 已提交
78

79 80
	public readonly textArea: FastDomNode<HTMLTextAreaElement>;
	public readonly textAreaCover: FastDomNode<HTMLElement>;
81
	private readonly _textAreaInput: TextAreaInput;
82

83
	constructor(context: ViewContext, viewController: ViewController, viewHelper: ITextAreaHandlerHelper) {
84
		super(context);
E
Erich Gamma 已提交
85

86 87
		this._viewController = viewController;
		this._viewHelper = viewHelper;
A
Alex Dima 已提交
88 89
		this._scrollLeft = 0;
		this._scrollTop = 0;
90

A
Alex Dima 已提交
91
		const options = this._context.configuration.options;
A
renames  
Alex Dima 已提交
92
		const layoutInfo = options.get(EditorOption.layoutInfo);
93

A
renames  
Alex Dima 已提交
94
		this._accessibilitySupport = options.get(EditorOption.accessibilitySupport);
A
Alex Dima 已提交
95 96 97
		this._contentLeft = layoutInfo.contentLeft;
		this._contentWidth = layoutInfo.contentWidth;
		this._contentHeight = layoutInfo.contentHeight;
98
		this._fontInfo = options.get(EditorOption.fontInfo);
A
Alex Dima 已提交
99
		this._lineHeight = options.get(EditorOption.lineHeight);
A
Alex Dima 已提交
100 101
		this._emptySelectionClipboard = options.get(EditorOption.emptySelectionClipboard);
		this._copyWithSyntaxHighlighting = options.get(EditorOption.copyWithSyntaxHighlighting);
102

103
		this._visibleTextArea = null;
104
		this._selections = [new Selection(1, 1, 1, 1)];
A
Alex Dima 已提交
105

106 107 108 109 110 111 112
		// Text Area (The focus will always be in the textarea when the cursor is blinking)
		this.textArea = createFastDomNode(document.createElement('textarea'));
		PartFingerprints.write(this.textArea, PartFingerprint.TextArea);
		this.textArea.setClassName('inputarea');
		this.textArea.setAttribute('wrap', 'off');
		this.textArea.setAttribute('autocorrect', 'off');
		this.textArea.setAttribute('autocapitalize', 'off');
113
		this.textArea.setAttribute('autocomplete', 'off');
114
		this.textArea.setAttribute('spellcheck', 'false');
115
		this.textArea.setAttribute('aria-label', this._getAriaLabel(options));
116 117 118 119 120
		this.textArea.setAttribute('role', 'textbox');
		this.textArea.setAttribute('aria-multiline', 'true');
		this.textArea.setAttribute('aria-haspopup', 'false');
		this.textArea.setAttribute('aria-autocomplete', 'both');

121
		if (platform.isWeb && options.get(EditorOption.readOnly)) {
122 123 124
			this.textArea.setAttribute('readonly', 'true');
		}

125 126 127
		this.textAreaCover = createFastDomNode(document.createElement('div'));
		this.textAreaCover.setPosition('absolute');

128 129 130 131 132 133 134 135 136 137 138 139
		const simpleModel: ISimpleModel = {
			getLineCount: (): number => {
				return this._context.model.getLineCount();
			},
			getLineMaxColumn: (lineNumber: number): number => {
				return this._context.model.getLineMaxColumn(lineNumber);
			},
			getValueInRange: (range: Range, eol: EndOfLinePreference): string => {
				return this._context.model.getValueInRange(range, eol);
			}
		};

140
		const textAreaInputHost: ITextAreaInputHost = {
141 142
			getDataToCopy: (generateHTML: boolean): ClipboardDataToCopy => {
				const rawTextToCopy = this._context.model.getPlainTextToCopy(this._selections, this._emptySelectionClipboard, platform.isWindows);
143 144 145
				const newLineCharacter = this._context.model.getEOL();

				const isFromEmptySelection = (this._emptySelectionClipboard && this._selections.length === 1 && this._selections[0].isEmpty());
146 147
				const multicursorText = (Array.isArray(rawTextToCopy) ? rawTextToCopy : null);
				const text = (Array.isArray(rawTextToCopy) ? rawTextToCopy.join(newLineCharacter) : rawTextToCopy);
A
Alex Dima 已提交
148

149 150 151 152 153
				let html: string | null | undefined = undefined;
				if (generateHTML) {
					if (CopyOptions.forceCopyWithSyntaxHighlighting || (this._copyWithSyntaxHighlighting && text.length < 65536)) {
						html = this._context.model.getHTMLToCopy(this._selections, this._emptySelectionClipboard);
					}
154
				}
155 156 157 158 159 160
				return {
					isFromEmptySelection,
					multicursorText,
					text,
					html
				};
A
Alex Dima 已提交
161
			},
162 163 164 165 166 167 168 169

			getScreenReaderContent: (currentState: TextAreaState): TextAreaState => {

				if (browser.isIPad) {
					// Do not place anything in the textarea for the iPad
					return TextAreaState.EMPTY;
				}

170
				if (this._accessibilitySupport === AccessibilitySupport.Disabled) {
171
					// We know for a fact that a screen reader is not attached
172
					// On OSX, we write the character before the cursor to allow for "long-press" composition
173
					// Also on OSX, we write the word before the cursor to allow for the Accessibility Keyboard to give good hints
174 175 176 177
					if (platform.isMacintosh) {
						const selection = this._selections[0];
						if (selection.isEmpty()) {
							const position = selection.getStartPosition();
178 179 180 181 182 183 184 185

							let textBefore = this._getWordBeforePosition(position);
							if (textBefore.length === 0) {
								textBefore = this._getCharacterBeforePosition(position);
							}

							if (textBefore.length > 0) {
								return new TextAreaState(textBefore, textBefore.length, textBefore.length, position, position);
186 187 188
							}
						}
					}
189 190 191
					return TextAreaState.EMPTY;
				}

192
				return PagedScreenReaderStrategy.fromEditorSelection(currentState, simpleModel, this._selections[0], this._accessibilitySupport === AccessibilitySupport.Unknown);
193 194 195 196
			},

			deduceModelPosition: (viewAnchorPosition: Position, deltaOffset: number, lineFeedCnt: number): Position => {
				return this._context.model.deduceModelPositionRelativeToViewPosition(viewAnchorPosition, deltaOffset, lineFeedCnt);
A
Alex Dima 已提交
197 198
			}
		};
199

200
		this._textAreaInput = this._register(new TextAreaInput(textAreaInputHost, this.textArea));
201 202 203 204 205 206 207 208 209 210

		this._register(this._textAreaInput.onKeyDown((e: IKeyboardEvent) => {
			this._viewController.emitKeyDown(e);
		}));

		this._register(this._textAreaInput.onKeyUp((e: IKeyboardEvent) => {
			this._viewController.emitKeyUp(e);
		}));

		this._register(this._textAreaInput.onPaste((e: IPasteData) => {
A
Alex Dima 已提交
211
			let pasteOnNewLine = false;
212
			let multicursorText: string[] | null = null;
213 214 215
			if (e.metadata) {
				pasteOnNewLine = (this._emptySelectionClipboard && !!e.metadata.isFromEmptySelection);
				multicursorText = (typeof e.metadata.multicursorText !== 'undefined' ? e.metadata.multicursorText : null);
A
Alex Dima 已提交
216
			}
217
			this._viewController.paste('keyboard', e.text, pasteOnNewLine, multicursorText);
218 219 220 221
		}));

		this._register(this._textAreaInput.onCut(() => {
			this._viewController.cut('keyboard');
A
Alex Dima 已提交
222
		}));
223 224

		this._register(this._textAreaInput.onType((e: ITypeData) => {
225
			if (e.replaceCharCnt) {
226
				this._viewController.replacePreviousChar('keyboard', e.text, e.replaceCharCnt);
227
			} else {
228
				this._viewController.type('keyboard', e.text);
229 230
			}
		}));
231

232 233 234 235
		this._register(this._textAreaInput.onSelectionChangeRequest((modelSelection: Selection) => {
			this._viewController.setSelection('keyboard', modelSelection);
		}));

236
		this._register(this._textAreaInput.onCompositionStart(() => {
A
Alex Dima 已提交
237 238
			const lineNumber = this._selections[0].startLineNumber;
			const column = this._selections[0].startColumn;
239

240
			this._context.privateViewEventBus.emit(new viewEvents.ViewRevealRangeRequestEvent(
241
				'keyboard',
A
Alex Dima 已提交
242
				new Range(lineNumber, column, lineNumber, column),
243
				viewEvents.VerticalRevealType.Simple,
244 245
				true,
				ScrollType.Immediate
A
Alex Dima 已提交
246
			));
247 248

			// Find range pixel position
249
			const visibleRange = this._viewHelper.visibleRangeForPositionRelativeToEditor(lineNumber, column);
250 251

			if (visibleRange) {
252 253
				this._visibleTextArea = new VisibleTextAreaData(
					this._context.viewLayout.getVerticalOffsetForLineNumber(lineNumber),
254 255 256
					visibleRange.left,
					canUseZeroSizeTextarea ? 0 : 1
				);
257
				this._render();
258 259 260
			}

			// Show the textarea
261
			this.textArea.setClassName('inputarea ime-input');
262

263
			this._viewController.compositionStart('keyboard');
264
		}));
265

266
		this._register(this._textAreaInput.onCompositionUpdate((e: ICompositionData) => {
267 268 269
			if (browser.isEdgeOrIE) {
				// Due to isEdgeOrIE (where the textarea was not cleared initially)
				// we cannot assume the text consists only of the composited text
A
Alex Dima 已提交
270
				this._visibleTextArea = this._visibleTextArea!.setWidth(0);
271 272
			} else {
				// adjust width by its size
A
Alex Dima 已提交
273
				this._visibleTextArea = this._visibleTextArea!.setWidth(measureText(e.data, this._fontInfo));
274
			}
275
			this._render();
276 277
		}));

278
		this._register(this._textAreaInput.onCompositionEnd(() => {
279

280 281
			this._visibleTextArea = null;
			this._render();
282

283
			this.textArea.setClassName('inputarea');
284
			this._viewController.compositionEnd('keyboard');
285
		}));
286

287 288 289 290 291 292 293
		this._register(this._textAreaInput.onFocus(() => {
			this._context.privateViewEventBus.emit(new viewEvents.ViewFocusChangedEvent(true));
		}));

		this._register(this._textAreaInput.onBlur(() => {
			this._context.privateViewEventBus.emit(new viewEvents.ViewFocusChangedEvent(false));
		}));
E
Erich Gamma 已提交
294 295
	}

296
	public dispose(): void {
A
Alex Dima 已提交
297
		super.dispose();
298 299
	}

300 301
	private _getWordBeforePosition(position: Position): string {
		const lineContent = this._context.model.getLineContent(position.lineNumber);
A
Alex Dima 已提交
302
		const wordSeparators = getMapForWordSeparators(this._context.configuration.options.get(EditorOption.wordSeparators));
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328

		let column = position.column;
		let distance = 0;
		while (column > 1) {
			const charCode = lineContent.charCodeAt(column - 2);
			const charClass = wordSeparators.get(charCode);
			if (charClass !== WordCharacterClass.Regular || distance > 50) {
				return lineContent.substring(column - 1, position.column - 1);
			}
			distance++;
			column--;
		}
		return lineContent.substring(0, position.column - 1);
	}

	private _getCharacterBeforePosition(position: Position): string {
		if (position.column > 1) {
			const lineContent = this._context.model.getLineContent(position.lineNumber);
			const charBefore = lineContent.charAt(position.column - 2);
			if (!strings.isHighSurrogate(charBefore.charCodeAt(0))) {
				return charBefore;
			}
		}
		return '';
	}

329 330 331 332 333 334 335 336
	private _getAriaLabel(options: IComputedEditorOptions): string {
		const accessibilitySupport = options.get(EditorOption.accessibilitySupport);
		if (accessibilitySupport === AccessibilitySupport.Disabled) {
			return nls.localize('accessibilityOffAriaLabel', "The editor is not accessible at this time. Press Alt+F1 for options.");
		}
		return options.get(EditorOption.ariaLabel);
	}

337 338
	// --- begin event handlers

A
Alex Dima 已提交
339
	public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean {
A
Alex Dima 已提交
340
		const options = this._context.configuration.options;
A
Alex Dima 已提交
341 342 343 344 345 346
		const layoutInfo = options.get(EditorOption.layoutInfo);

		this._accessibilitySupport = options.get(EditorOption.accessibilitySupport);
		this._contentLeft = layoutInfo.contentLeft;
		this._contentWidth = layoutInfo.contentWidth;
		this._contentHeight = layoutInfo.contentHeight;
347
		this._fontInfo = options.get(EditorOption.fontInfo);
A
Alex Dima 已提交
348
		this._lineHeight = options.get(EditorOption.lineHeight);
A
Alex Dima 已提交
349 350
		this._emptySelectionClipboard = options.get(EditorOption.emptySelectionClipboard);
		this._copyWithSyntaxHighlighting = options.get(EditorOption.copyWithSyntaxHighlighting);
351
		this.textArea.setAttribute('aria-label', this._getAriaLabel(options));
352

353 354 355 356 357 358
		if (platform.isWeb && e.hasChanged(EditorOption.readOnly)) {
			if (options.get(EditorOption.readOnly)) {
				this.textArea.setAttribute('readonly', 'true');
			} else {
				this.textArea.removeAttribute('readonly');
			}
359 360
		}

A
renames  
Alex Dima 已提交
361
		if (e.hasChanged(EditorOption.accessibilitySupport)) {
362 363
			this._textAreaInput.writeScreenReaderContent('strategy changed');
		}
364

365
		return true;
366
	}
367 368
	public onCursorStateChanged(e: viewEvents.ViewCursorStateChangedEvent): boolean {
		this._selections = e.selections.slice(0);
369
		this._textAreaInput.writeScreenReaderContent('selection changed');
370
		return true;
371
	}
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
	public onDecorationsChanged(e: viewEvents.ViewDecorationsChangedEvent): boolean {
		// true for inline decorations that can end up relayouting text
		return true;
	}
	public onFlushed(e: viewEvents.ViewFlushedEvent): boolean {
		return true;
	}
	public onLinesChanged(e: viewEvents.ViewLinesChangedEvent): boolean {
		return true;
	}
	public onLinesDeleted(e: viewEvents.ViewLinesDeletedEvent): boolean {
		return true;
	}
	public onLinesInserted(e: viewEvents.ViewLinesInsertedEvent): boolean {
		return true;
	}
388
	public onScrollChanged(e: viewEvents.ViewScrollChangedEvent): boolean {
389 390
		this._scrollLeft = e.scrollLeft;
		this._scrollTop = e.scrollTop;
391 392 393
		return true;
	}
	public onZonesChanged(e: viewEvents.ViewZonesChangedEvent): boolean {
394
		return true;
395 396
	}

397 398
	// --- end event handlers

399 400
	// --- begin view API

A
Alex Dima 已提交
401 402 403 404 405 406 407 408
	public isFocused(): boolean {
		return this._textAreaInput.isFocused();
	}

	public focusTextArea(): void {
		this._textAreaInput.focusTextArea();
	}

409
	// --- end view API
410

411
	private _primaryCursorVisibleRange: HorizontalRange | null = null;
412

413
	public prepareRender(ctx: RenderingContext): void {
414 415
		const primaryCursorPosition = new Position(this._selections[0].positionLineNumber, this._selections[0].positionColumn);
		this._primaryCursorVisibleRange = ctx.visibleRangeForPosition(primaryCursorPosition);
416 417 418
	}

	public render(ctx: RestrictedRenderingContext): void {
419
		this._textAreaInput.writeScreenReaderContent('render');
420 421 422 423 424 425
		this._render();
	}

	private _render(): void {
		if (this._visibleTextArea) {
			// The text area is visible for composition reasons
426 427 428 429
			this._renderInsideEditor(
				this._visibleTextArea.top - this._scrollTop,
				this._contentLeft + this._visibleTextArea.left - this._scrollLeft,
				this._visibleTextArea.width,
430 431
				this._lineHeight,
				true
432 433 434
			);
			return;
		}
435

436 437 438 439 440
		if (!this._primaryCursorVisibleRange) {
			// The primary cursor is outside the viewport => place textarea to the top left
			this._renderAtTopLeft();
			return;
		}
441

442 443 444 445 446 447 448
		const left = this._contentLeft + this._primaryCursorVisibleRange.left - this._scrollLeft;
		if (left < this._contentLeft || left > this._contentLeft + this._contentWidth) {
			// cursor is outside the viewport
			this._renderAtTopLeft();
			return;
		}

449
		const top = this._context.viewLayout.getVerticalOffsetForLineNumber(this._selections[0].positionLineNumber) - this._scrollTop;
450 451 452 453 454 455 456
		if (top < 0 || top > this._contentHeight) {
			// cursor is outside the viewport
			this._renderAtTopLeft();
			return;
		}

		// The primary cursor is in the viewport (at least vertically) => place textarea on the cursor
457 458 459 460 461
		this._renderInsideEditor(
			top, left,
			canUseZeroSizeTextarea ? 0 : 1, canUseZeroSizeTextarea ? 0 : 1,
			false
		);
462 463
	}

464
	private _renderInsideEditor(top: number, left: number, width: number, height: number, useEditorFont: boolean): void {
465 466 467
		const ta = this.textArea;
		const tac = this.textAreaCover;

468 469 470 471
		if (useEditorFont) {
			Configuration.applyFontInfo(ta, this._fontInfo);
		} else {
			ta.setFontSize(1);
472
			ta.setLineHeight(this._fontInfo.lineHeight);
473 474
		}

475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
		ta.setTop(top);
		ta.setLeft(left);
		ta.setWidth(width);
		ta.setHeight(height);

		tac.setTop(0);
		tac.setLeft(0);
		tac.setWidth(0);
		tac.setHeight(0);
	}

	private _renderAtTopLeft(): void {
		const ta = this.textArea;
		const tac = this.textAreaCover;

490
		Configuration.applyFontInfo(ta, this._fontInfo);
491 492 493 494 495 496 497 498 499 500 501 502
		ta.setTop(0);
		ta.setLeft(0);
		tac.setTop(0);
		tac.setLeft(0);

		if (canUseZeroSizeTextarea) {
			ta.setWidth(0);
			ta.setHeight(0);
			tac.setWidth(0);
			tac.setHeight(0);
			return;
		}
503

504
		// (in WebKit the textarea is 1px by 1px because it cannot handle input to a 0x0 textarea)
P
Paul.K.Zhang 已提交
505
		// specifically, when doing Korean IME, setting the textarea to 0x0 breaks IME badly.
506

507 508 509 510 511
		ta.setWidth(1);
		ta.setHeight(1);
		tac.setWidth(1);
		tac.setHeight(1);

A
Alex Dima 已提交
512 513
		const options = this._context.configuration.options;

A
Alex Dima 已提交
514
		if (options.get(EditorOption.glyphMargin)) {
A
Alex Dima 已提交
515
			tac.setClassName('monaco-editor-background textAreaCover ' + Margin.OUTER_CLASS_NAME);
516
		} else {
A
Alex Dima 已提交
517
			if (options.get(EditorOption.lineNumbers).renderType !== RenderLineNumbersType.Off) {
518
				tac.setClassName('monaco-editor-background textAreaCover ' + LineNumbersOverlay.CLASS_NAME);
519
			} else {
520
				tac.setClassName('monaco-editor-background textAreaCover');
521 522 523
			}
		}
	}
524
}
A
Alex Dima 已提交
525 526 527 528

function measureText(text: string, fontInfo: BareFontInfo): number {
	// adjust width by its size
	const canvasElem = <HTMLCanvasElement>document.createElement('canvas');
A
Alex Dima 已提交
529
	const context = canvasElem.getContext('2d')!;
A
Alex Dima 已提交
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
	context.font = createFontString(fontInfo);
	const metrics = context.measureText(text);

	if (browser.isFirefox) {
		return metrics.width + 2; // +2 for Japanese...
	} else {
		return metrics.width;
	}
}

function createFontString(bareFontInfo: BareFontInfo): string {
	return doCreateFontString('normal', bareFontInfo.fontWeight, bareFontInfo.fontSize, bareFontInfo.lineHeight, bareFontInfo.fontFamily);
}

function doCreateFontString(fontStyle: string, fontWeight: string, fontSize: number, lineHeight: number, fontFamily: string): string {
	// The full font syntax is:
	// style | variant | weight | stretch | size/line-height | fontFamily
	// (https://developer.mozilla.org/en-US/docs/Web/CSS/font)
	// But it appears Edge and IE11 cannot properly parse `stretch`.
	return `${fontStyle} normal ${fontWeight} ${fontSize}px / ${lineHeight}px ${fontFamily}`;
}