Add editor.disableMonospaceOptimizations (closes #19062)

This commit is contained in:
Alex Dima 2017-01-26 11:03:48 +01:00
parent 291881c86d
commit cf07be7af0
7 changed files with 48 additions and 15 deletions

View file

@ -70,7 +70,7 @@ export class ViewLine implements IVisibleLineData {
private _renderWhitespace: 'none' | 'boundary' | 'all';
private _renderControlCharacters: boolean;
private _spaceWidth: number;
private _fontIsMonospace: boolean;
private _useMonospaceOptimizations: boolean;
private _lineHeight: number;
private _stopRenderingLineAfter: number;
@ -83,7 +83,10 @@ export class ViewLine implements IVisibleLineData {
this._renderWhitespace = this._context.configuration.editor.viewInfo.renderWhitespace;
this._renderControlCharacters = this._context.configuration.editor.viewInfo.renderControlCharacters;
this._spaceWidth = this._context.configuration.editor.fontInfo.spaceWidth;
this._fontIsMonospace = this._context.configuration.editor.fontInfo.isMonospace;
this._useMonospaceOptimizations = (
this._context.configuration.editor.fontInfo.isMonospace
&& !this._context.configuration.editor.viewInfo.disableMonospaceOptimizations
);
this._lineHeight = this._context.configuration.editor.lineHeight;
this._stopRenderingLineAfter = this._context.configuration.editor.viewInfo.stopRenderingLineAfter;
@ -126,10 +129,20 @@ export class ViewLine implements IVisibleLineData {
this._isMaybeInvalid = true;
this._renderControlCharacters = this._context.configuration.editor.viewInfo.renderControlCharacters;
}
if (e.viewInfo.disableMonospaceOptimizations) {
this._isMaybeInvalid = true;
this._useMonospaceOptimizations = (
this._context.configuration.editor.fontInfo.isMonospace
&& !this._context.configuration.editor.viewInfo.disableMonospaceOptimizations
);
}
if (e.fontInfo) {
this._isMaybeInvalid = true;
this._spaceWidth = this._context.configuration.editor.fontInfo.spaceWidth;
this._fontIsMonospace = this._context.configuration.editor.fontInfo.isMonospace;
this._useMonospaceOptimizations = (
this._context.configuration.editor.fontInfo.isMonospace
&& !this._context.configuration.editor.viewInfo.disableMonospaceOptimizations
);
}
if (e.lineHeight) {
this._isMaybeInvalid = true;
@ -153,7 +166,7 @@ export class ViewLine implements IVisibleLineData {
const lineContent = model.getLineContent(lineNumber);
let renderLineInput = new RenderLineInput(
this._fontIsMonospace,
this._useMonospaceOptimizations,
lineContent,
model.mightContainRTL(),
model.getLineMinColumn(lineNumber) - 1,
@ -174,7 +187,7 @@ export class ViewLine implements IVisibleLineData {
const output = renderViewLine(renderLineInput);
let renderedViewLine: IRenderedViewLine = null;
if (canUseFastRenderedViewLine && this._fontIsMonospace && !output.containsForeignElements) {
if (canUseFastRenderedViewLine && this._useMonospaceOptimizations && !output.containsForeignElements) {
let isRegularASCII = true;
if (model.mightContainNonBasicASCII()) {
isRegularASCII = strings.isBasicASCII(lineContent);

View file

@ -1894,7 +1894,7 @@ class InlineViewZonesComputer extends ViewZonesComputer {
let actualDecorations = Decoration.filter(decorations, lineNumber, 1, lineContent.length + 1);
let r = renderViewLine(new RenderLineInput(
config.fontInfo.isMonospace,
(config.fontInfo.isMonospace && !config.viewInfo.disableMonospaceOptimizations),
lineContent,
originalModel.mightContainRTL(),
0,

View file

@ -252,6 +252,7 @@ class InternalEditorOptionsHelper {
let viewInfo = new editorCommon.InternalEditorViewOptions({
theme: opts.theme,
canUseTranslate3d: canUseTranslate3d,
disableMonospaceOptimizations: toBoolean(opts.disableMonospaceOptimizations),
experimentalScreenReader: toBoolean(opts.experimentalScreenReader),
rulers: toSortedIntegerArray(opts.rulers),
ariaLabel: String(opts.ariaLabel),

View file

@ -63,6 +63,7 @@ class ConfigClass implements IConfiguration {
cursorStyle: 'line',
fontLigatures: false,
disableTranslate3d: false,
disableMonospaceOptimizations: false,
hideCursorInOverviewRuler: false,
scrollBeyondLastLine: true,
automaticLayout: false,

View file

@ -292,6 +292,11 @@ export interface IEditorOptions {
* Defaults to false.
*/
disableTranslate3d?: boolean;
/**
* Disable the optimizations for monospace fonts.
* Defaults to false.
*/
disableMonospaceOptimizations?: boolean;
/**
* Should the cursor be hidden in the overview ruler.
* Defaults to false.
@ -663,6 +668,7 @@ export class InternalEditorViewOptions {
readonly theme: string;
readonly canUseTranslate3d: boolean;
readonly disableMonospaceOptimizations: boolean;
readonly experimentalScreenReader: boolean;
readonly rulers: number[];
readonly ariaLabel: string;
@ -694,6 +700,7 @@ export class InternalEditorViewOptions {
constructor(source: {
theme: string;
canUseTranslate3d: boolean;
disableMonospaceOptimizations: boolean;
experimentalScreenReader: boolean;
rulers: number[];
ariaLabel: string;
@ -721,6 +728,7 @@ export class InternalEditorViewOptions {
}) {
this.theme = String(source.theme);
this.canUseTranslate3d = Boolean(source.canUseTranslate3d);
this.disableMonospaceOptimizations = Boolean(source.disableMonospaceOptimizations);
this.experimentalScreenReader = Boolean(source.experimentalScreenReader);
this.rulers = InternalEditorViewOptions._toSortedIntegerArray(source.rulers);
this.ariaLabel = String(source.ariaLabel);
@ -782,6 +790,7 @@ export class InternalEditorViewOptions {
return (
this.theme === other.theme
&& this.canUseTranslate3d === other.canUseTranslate3d
&& this.disableMonospaceOptimizations === other.disableMonospaceOptimizations
&& this.experimentalScreenReader === other.experimentalScreenReader
&& InternalEditorViewOptions._numberArraysEqual(this.rulers, other.rulers)
&& this.ariaLabel === other.ariaLabel
@ -816,6 +825,7 @@ export class InternalEditorViewOptions {
return {
theme: this.theme !== newOpts.theme,
canUseTranslate3d: this.canUseTranslate3d !== newOpts.canUseTranslate3d,
disableMonospaceOptimizations: this.disableMonospaceOptimizations !== newOpts.disableMonospaceOptimizations,
experimentalScreenReader: this.experimentalScreenReader !== newOpts.experimentalScreenReader,
rulers: (!InternalEditorViewOptions._numberArraysEqual(this.rulers, newOpts.rulers)),
ariaLabel: this.ariaLabel !== newOpts.ariaLabel,
@ -854,6 +864,7 @@ export class InternalEditorViewOptions {
export interface IViewConfigurationChangedEvent {
readonly theme: boolean;
readonly canUseTranslate3d: boolean;
readonly disableMonospaceOptimizations: boolean;
readonly experimentalScreenReader: boolean;
readonly rulers: boolean;
readonly ariaLabel: boolean;

View file

@ -17,7 +17,7 @@ export const enum RenderWhitespace {
export class RenderLineInput {
public readonly fontIsMonospace: boolean;
public readonly useMonospaceOptimizations: boolean;
public readonly lineContent: string;
public readonly mightContainRTL: boolean;
public readonly fauxIndentLength: number;
@ -30,7 +30,7 @@ export class RenderLineInput {
public readonly renderControlCharacters: boolean;
constructor(
fontIsMonospace: boolean,
useMonospaceOptimizations: boolean,
lineContent: string,
mightContainRTL: boolean,
fauxIndentLength: number,
@ -42,7 +42,7 @@ export class RenderLineInput {
renderWhitespace: 'none' | 'boundary' | 'all',
renderControlCharacters: boolean,
) {
this.fontIsMonospace = fontIsMonospace;
this.useMonospaceOptimizations = useMonospaceOptimizations;
this.lineContent = lineContent;
this.mightContainRTL = mightContainRTL;
this.fauxIndentLength = fauxIndentLength;
@ -63,7 +63,7 @@ export class RenderLineInput {
public equals(other: RenderLineInput): boolean {
return (
this.fontIsMonospace === other.fontIsMonospace
this.useMonospaceOptimizations === other.useMonospaceOptimizations
&& this.lineContent === other.lineContent
&& this.mightContainRTL === other.mightContainRTL
&& this.fauxIndentLength === other.fauxIndentLength
@ -249,7 +249,7 @@ class ResolvedRenderLineInput {
}
function resolveRenderLineInput(input: RenderLineInput): ResolvedRenderLineInput {
const fontIsMonospace = input.fontIsMonospace;
const useMonospaceOptimizations = input.useMonospaceOptimizations;
const lineContent = input.lineContent;
let isOverflowing: boolean;
@ -265,7 +265,7 @@ function resolveRenderLineInput(input: RenderLineInput): ResolvedRenderLineInput
let tokens = removeOverflowing(input.lineTokens, len);
if (input.renderWhitespace === RenderWhitespace.All || input.renderWhitespace === RenderWhitespace.Boundary) {
tokens = _applyRenderWhitespace(lineContent, len, tokens, input.fauxIndentLength, input.tabSize, fontIsMonospace, input.renderWhitespace === RenderWhitespace.Boundary);
tokens = _applyRenderWhitespace(lineContent, len, tokens, input.fauxIndentLength, input.tabSize, useMonospaceOptimizations, input.renderWhitespace === RenderWhitespace.Boundary);
}
let containsForeignElements = false;
if (input.lineDecorations.length > 0) {
@ -287,7 +287,7 @@ function resolveRenderLineInput(input: RenderLineInput): ResolvedRenderLineInput
}
return new ResolvedRenderLineInput(
fontIsMonospace,
useMonospaceOptimizations,
lineContent,
len,
isOverflowing,
@ -369,7 +369,7 @@ function splitLargeTokens(tokens: ViewLineToken[]): ViewLineToken[] {
* Moreover, a token is created for every visual indent because on some fonts the glyphs used for rendering whitespace (→ or ·) do not have the same width as  .
* The rendering phase will generate `style="width:..."` for these tokens.
*/
function _applyRenderWhitespace(lineContent: string, len: number, tokens: ViewLineToken[], fauxIndentLength: number, tabSize: number, fontIsMonospace: boolean, onlyBoundary: boolean): ViewLineToken[] {
function _applyRenderWhitespace(lineContent: string, len: number, tokens: ViewLineToken[], fauxIndentLength: number, tabSize: number, useMonospaceOptimizations: boolean, onlyBoundary: boolean): ViewLineToken[] {
let result: ViewLineToken[] = [], resultLen = 0;
let tokenIndex = 0;
@ -431,7 +431,7 @@ function _applyRenderWhitespace(lineContent: string, len: number, tokens: ViewLi
if (wasInWhitespace) {
// was in whitespace token
if (!isInWhitespace || (!fontIsMonospace && tmpIndent >= tabSize)) {
if (!isInWhitespace || (!useMonospaceOptimizations && tmpIndent >= tabSize)) {
// leaving whitespace token or entering a new indent
result[resultLen++] = new ViewLineToken(charIndex, 'vs-whitespace');
tmpIndent = tmpIndent % tabSize;

7
src/vs/monaco.d.ts vendored
View file

@ -1210,6 +1210,11 @@ declare module monaco.editor {
* Defaults to false.
*/
disableTranslate3d?: boolean;
/**
* Disable the optimizations for monospace fonts.
* Defaults to false.
*/
disableMonospaceOptimizations?: boolean;
/**
* Should the cursor be hidden in the overview ruler.
* Defaults to false.
@ -1474,6 +1479,7 @@ declare module monaco.editor {
readonly _internalEditorViewOptionsBrand: void;
readonly theme: string;
readonly canUseTranslate3d: boolean;
readonly disableMonospaceOptimizations: boolean;
readonly experimentalScreenReader: boolean;
readonly rulers: number[];
readonly ariaLabel: string;
@ -1503,6 +1509,7 @@ declare module monaco.editor {
export interface IViewConfigurationChangedEvent {
readonly theme: boolean;
readonly canUseTranslate3d: boolean;
readonly disableMonospaceOptimizations: boolean;
readonly experimentalScreenReader: boolean;
readonly rulers: boolean;
readonly ariaLabel: boolean;