diff --git a/src/vs/editor/browser/view/domLineBreaksComputer.ts b/src/vs/editor/browser/view/domLineBreaksComputer.ts index 11db5d68493340afd23b576726eec5a5ac78bb9f..ab567c36c9fe65134f73df29e0efef0b1d552c3e 100644 --- a/src/vs/editor/browser/view/domLineBreaksComputer.ts +++ b/src/vs/editor/browser/view/domLineBreaksComputer.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { ILineBreaksComputerFactory, LineBreakData, ILineBreaksComputer } from 'vs/editor/common/viewModel/splitLinesCollection'; -import { IComputedEditorOptions, EditorOption, WrappingIndent } from 'vs/editor/common/config/editorOptions'; +import { WrappingIndent } from 'vs/editor/common/config/editorOptions'; import { FontInfo } from 'vs/editor/common/config/fontInfo'; import { createStringBuilder, IStringBuilder } from 'vs/editor/common/core/stringBuilder'; import { CharCode } from 'vs/base/common/charCode'; @@ -13,22 +13,16 @@ import { Configuration } from 'vs/editor/browser/config/configuration'; export class DOMLineBreaksComputerFactory implements ILineBreaksComputerFactory { - public static create(options: IComputedEditorOptions): DOMLineBreaksComputerFactory { - return new DOMLineBreaksComputerFactory( - options.get(EditorOption.fontInfo) - ); + public static create(): DOMLineBreaksComputerFactory { + return new DOMLineBreaksComputerFactory(); } - private _fontInfo: FontInfo; - - constructor(fontInfo: FontInfo) { - this._fontInfo = fontInfo; + constructor() { } - public createLineBreaksComputer(tabSize: number, wrappingColumn: number, columnsForFullWidthChar: number, wrappingIndent: WrappingIndent): ILineBreaksComputer { + public createLineBreaksComputer(fontInfo: FontInfo, tabSize: number, wrappingColumn: number, wrappingIndent: WrappingIndent): ILineBreaksComputer { tabSize = tabSize | 0; //@perf wrappingColumn = +wrappingColumn; //@perf - columnsForFullWidthChar = +columnsForFullWidthChar; //@perf let requests: string[] = []; return { @@ -36,7 +30,7 @@ export class DOMLineBreaksComputerFactory implements ILineBreaksComputerFactory requests.push(lineText); }, finalize: () => { - return createLineBreaks(requests, this._fontInfo, tabSize, wrappingColumn, wrappingIndent); + return createLineBreaks(requests, fontInfo, tabSize, wrappingColumn, wrappingIndent); } }; } diff --git a/src/vs/editor/browser/widget/codeEditorWidget.ts b/src/vs/editor/browser/widget/codeEditorWidget.ts index 6d584cb146ceaab8ebc362c6330e36c051e7765c..2f8f5cf4f98d2aadd94f8f253fb4d474e84cf1e5 100644 --- a/src/vs/editor/browser/widget/codeEditorWidget.ts +++ b/src/vs/editor/browser/widget/codeEditorWidget.ts @@ -1342,7 +1342,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE this._id, this._configuration, model, - DOMLineBreaksComputerFactory.create(this._configuration.options), + DOMLineBreaksComputerFactory.create(), MonospaceLineBreaksComputerFactory.create(this._configuration.options), (callback) => dom.scheduleAtNextAnimationFrame(callback) ); diff --git a/src/vs/editor/common/viewModel/monospaceLineBreaksComputer.ts b/src/vs/editor/common/viewModel/monospaceLineBreaksComputer.ts index 546464c2636583b4fbcdb0058650af7542ded69c..97a3c4a7655e85312816b487e0d91d6e652f8578 100644 --- a/src/vs/editor/common/viewModel/monospaceLineBreaksComputer.ts +++ b/src/vs/editor/common/viewModel/monospaceLineBreaksComputer.ts @@ -8,6 +8,7 @@ import * as strings from 'vs/base/common/strings'; import { WrappingIndent, IComputedEditorOptions, EditorOption } from 'vs/editor/common/config/editorOptions'; import { CharacterClassifier } from 'vs/editor/common/core/characterClassifier'; import { ILineBreaksComputerFactory, LineBreakData, ILineBreaksComputer } from 'vs/editor/common/viewModel/splitLinesCollection'; +import { FontInfo } from 'vs/editor/common/config/fontInfo'; const enum CharacterClass { NONE = 0, @@ -69,10 +70,9 @@ export class MonospaceLineBreaksComputerFactory implements ILineBreaksComputerFa this.classifier = new WrappingCharacterClassifier(breakBeforeChars, breakAfterChars); } - public createLineBreaksComputer(tabSize: number, wrappingColumn: number, columnsForFullWidthChar: number, wrappingIndent: WrappingIndent): ILineBreaksComputer { + public createLineBreaksComputer(fontInfo: FontInfo, tabSize: number, wrappingColumn: number, wrappingIndent: WrappingIndent): ILineBreaksComputer { tabSize = tabSize | 0; //@perf wrappingColumn = +wrappingColumn; //@perf - columnsForFullWidthChar = +columnsForFullWidthChar; //@perf let requests: string[] = []; let previousBreakingData: (LineBreakData | null)[] = []; @@ -82,6 +82,7 @@ export class MonospaceLineBreaksComputerFactory implements ILineBreaksComputerFa previousBreakingData.push(previousLineBreakData); }, finalize: () => { + const columnsForFullWidthChar = fontInfo.typicalFullwidthCharacterWidth / fontInfo.typicalHalfwidthCharacterWidth; //@perf let result: (LineBreakData | null)[] = []; for (let i = 0, len = requests.length; i < len; i++) { const previousLineBreakData = previousBreakingData[i]; diff --git a/src/vs/editor/common/viewModel/splitLinesCollection.ts b/src/vs/editor/common/viewModel/splitLinesCollection.ts index 37a9e6a02c66d9d3f011b51c0da3e703e5c7899d..bee048ac90af662cbfb431bee47772604de00c14 100644 --- a/src/vs/editor/common/viewModel/splitLinesCollection.ts +++ b/src/vs/editor/common/viewModel/splitLinesCollection.ts @@ -15,6 +15,7 @@ import { PrefixSumIndexOfResult } from 'vs/editor/common/viewModel/prefixSumComp import { ICoordinatesConverter, IOverviewRulerDecorations, ViewLineData } from 'vs/editor/common/viewModel/viewModel'; import { ITheme } from 'vs/platform/theme/common/themeService'; import { IDisposable } from 'vs/base/common/lifecycle'; +import { FontInfo } from 'vs/editor/common/config/fontInfo'; export class OutputPosition { outputLineIndex: number; @@ -75,7 +76,7 @@ export interface ILineBreaksComputer { } export interface ILineBreaksComputerFactory { - createLineBreaksComputer(tabSize: number, wrappingColumn: number, columnsForFullWidthChar: number, wrappingIndent: WrappingIndent): ILineBreaksComputer; + createLineBreaksComputer(fontInfo: FontInfo, tabSize: number, wrappingColumn: number, wrappingIndent: WrappingIndent): ILineBreaksComputer; } export interface ISimpleModel { @@ -108,7 +109,7 @@ export interface ISplitLine { export interface IViewModelLinesCollection extends IDisposable { createCoordinatesConverter(): ICoordinatesConverter; - setWrappingSettings(wrappingIndent: WrappingIndent, wrappingColumn: number, columnsForFullWidthChar: number): boolean; + setWrappingSettings(fontInfo: FontInfo, wrappingColumn: number, wrappingIndent: WrappingIndent): boolean; setTabSize(newTabSize: number): boolean; getHiddenAreas(): Range[]; setHiddenAreas(_ranges: Range[]): boolean; @@ -274,10 +275,10 @@ export class SplitLinesCollection implements IViewModelLinesCollection { private readonly _domLineBreaksComputerFactory: ILineBreaksComputerFactory; private readonly _monospaceLineBreaksComputerFactory: ILineBreaksComputerFactory; + private fontInfo: FontInfo; + private tabSize: number; private wrappingColumn: number; - private columnsForFullWidthChar: number; private wrappingIndent: WrappingIndent; - private tabSize: number; private lines!: ISplitLine[]; private prefixSumComputer!: LineNumberMapper; @@ -288,18 +289,18 @@ export class SplitLinesCollection implements IViewModelLinesCollection { model: ITextModel, domLineBreaksComputerFactory: ILineBreaksComputerFactory, monospaceLineBreaksComputerFactory: ILineBreaksComputerFactory, + fontInfo: FontInfo, tabSize: number, wrappingColumn: number, - columnsForFullWidthChar: number, wrappingIndent: WrappingIndent ) { this.model = model; this._validModelVersionId = -1; this._domLineBreaksComputerFactory = domLineBreaksComputerFactory; this._monospaceLineBreaksComputerFactory = monospaceLineBreaksComputerFactory; + this.fontInfo = fontInfo; this.tabSize = tabSize; this.wrappingColumn = wrappingColumn; - this.columnsForFullWidthChar = columnsForFullWidthChar; this.wrappingIndent = wrappingIndent; this._constructLines(/*resetHiddenAreas*/true, null); @@ -482,16 +483,19 @@ export class SplitLinesCollection implements IViewModelLinesCollection { return true; } - public setWrappingSettings(wrappingIndent: WrappingIndent, wrappingColumn: number, columnsForFullWidthChar: number): boolean { - if (this.wrappingIndent === wrappingIndent && this.wrappingColumn === wrappingColumn && this.columnsForFullWidthChar === columnsForFullWidthChar) { + public setWrappingSettings(fontInfo: FontInfo, wrappingColumn: number, wrappingIndent: WrappingIndent): boolean { + const equalFontInfo = this.fontInfo.equals(fontInfo); + const equalWrappingColumn = (this.wrappingColumn === wrappingColumn); + const equalWrappingIndent = (this.wrappingIndent === wrappingIndent); + if (equalFontInfo && equalWrappingColumn && equalWrappingIndent) { return false; } - const onlyWrappingColumnChanged = (this.wrappingIndent === wrappingIndent && this.wrappingColumn !== wrappingColumn && this.columnsForFullWidthChar === columnsForFullWidthChar); + const onlyWrappingColumnChanged = (equalFontInfo && !equalWrappingColumn && equalWrappingIndent); - this.wrappingIndent = wrappingIndent; + this.fontInfo = fontInfo; this.wrappingColumn = wrappingColumn; - this.columnsForFullWidthChar = columnsForFullWidthChar; + this.wrappingIndent = wrappingIndent; let previousLineBreaks: ((LineBreakData | null)[]) | null = null; if (onlyWrappingColumnChanged) { @@ -512,7 +516,7 @@ export class SplitLinesCollection implements IViewModelLinesCollection { ? this._domLineBreaksComputerFactory : this._monospaceLineBreaksComputerFactory ); - return lineBreaksComputerFactory.createLineBreaksComputer(this.tabSize, this.wrappingColumn, this.columnsForFullWidthChar, this.wrappingIndent); + return lineBreaksComputerFactory.createLineBreaksComputer(this.fontInfo, this.tabSize, this.wrappingColumn, this.wrappingIndent); } public onModelFlushed(): void { @@ -1453,7 +1457,7 @@ export class IdentityLinesCollection implements IViewModelLinesCollection { return false; } - public setWrappingSettings(_wrappingIndent: WrappingIndent, _wrappingColumn: number, _columnsForFullWidthChar: number): boolean { + public setWrappingSettings(_fontInfo: FontInfo, _wrappingColumn: number, _wrappingIndent: WrappingIndent): boolean { return false; } diff --git a/src/vs/editor/common/viewModel/viewModelImpl.ts b/src/vs/editor/common/viewModel/viewModelImpl.ts index 2e9c57986ddec11f5711fc4b0359b3455b94bbfe..f6b5d5eeb4f9282d2eb6d5ef28790d9e02d0cbe5 100644 --- a/src/vs/editor/common/viewModel/viewModelImpl.ts +++ b/src/vs/editor/common/viewModel/viewModelImpl.ts @@ -75,9 +75,9 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel this.model, domLineBreaksComputerFactory, monospaceLineBreaksComputerFactory, + fontInfo, this.model.getOptions().tabSize, wrappingInfo.wrappingColumn, - fontInfo.typicalFullwidthCharacterWidth / fontInfo.typicalHalfwidthCharacterWidth, wrappingIndent ); } @@ -157,7 +157,7 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel const fontInfo = options.get(EditorOption.fontInfo); const wrappingIndent = options.get(EditorOption.wrappingIndent); - if (this.lines.setWrappingSettings(wrappingIndent, wrappingInfo.wrappingColumn, fontInfo.typicalFullwidthCharacterWidth / fontInfo.typicalHalfwidthCharacterWidth)) { + if (this.lines.setWrappingSettings(fontInfo, wrappingInfo.wrappingColumn, wrappingIndent)) { eventsCollector.emit(new viewEvents.ViewFlushedEvent()); eventsCollector.emit(new viewEvents.ViewLineMappingChangedEvent()); eventsCollector.emit(new viewEvents.ViewDecorationsChangedEvent()); diff --git a/src/vs/editor/test/common/viewModel/monospaceLineBreaksComputer.test.ts b/src/vs/editor/test/common/viewModel/monospaceLineBreaksComputer.test.ts index a95095bbc9933c43df92d768cc391df0800de93f..b0bacb0768bf9195159e8c1f4db8becec15ed9e0 100644 --- a/src/vs/editor/test/common/viewModel/monospaceLineBreaksComputer.test.ts +++ b/src/vs/editor/test/common/viewModel/monospaceLineBreaksComputer.test.ts @@ -6,6 +6,7 @@ import * as assert from 'assert'; import { WrappingIndent, EditorOptions } from 'vs/editor/common/config/editorOptions'; import { MonospaceLineBreaksComputerFactory } from 'vs/editor/common/viewModel/monospaceLineBreaksComputer'; import { ILineBreaksComputerFactory, LineBreakData } from 'vs/editor/common/viewModel/splitLinesCollection'; +import { FontInfo } from 'vs/editor/common/config/fontInfo'; function parseAnnotatedText(annotatedText: string): { text: string; indices: number[]; } { let text = ''; @@ -43,7 +44,22 @@ function toAnnotatedText(text: string, lineBreakData: LineBreakData | null): str } function getLineBreakData(factory: ILineBreaksComputerFactory, tabSize: number, breakAfter: number, columnsForFullWidthChar: number, wrappingIndent: WrappingIndent, text: string, previousLineBreakData: LineBreakData | null): LineBreakData | null { - const lineBreaksComputer = factory.createLineBreaksComputer(tabSize, breakAfter, columnsForFullWidthChar, wrappingIndent); + const fontInfo = new FontInfo({ + zoomLevel: 0, + fontFamily: 'testFontFamily', + fontWeight: 'normal', + fontSize: 14, + fontFeatureSettings: '', + lineHeight: 19, + letterSpacing: 0, + isMonospace: true, + typicalHalfwidthCharacterWidth: 7, + typicalFullwidthCharacterWidth: 14, + canUseHalfwidthRightwardsArrow: true, + spaceWidth: 7, + maxDigitWidth: 7 + }, false); + const lineBreaksComputer = factory.createLineBreaksComputer(fontInfo, tabSize, breakAfter, wrappingIndent); const previousLineBreakDataClone = previousLineBreakData ? new LineBreakData(previousLineBreakData.breakOffsets.slice(0), previousLineBreakData.breakOffsetsVisibleColumn.slice(0), previousLineBreakData.wrappedTextIndentLength) : null; lineBreaksComputer.addRequest(text, previousLineBreakDataClone); return lineBreaksComputer.finalize()[0]; diff --git a/src/vs/editor/test/common/viewModel/splitLinesCollection.test.ts b/src/vs/editor/test/common/viewModel/splitLinesCollection.test.ts index 0f6be3855ad076e21f5a5f01894d21b43000a171..53234a03a3a117a06dd01fe8ccbf22d553a1b0ff 100644 --- a/src/vs/editor/test/common/viewModel/splitLinesCollection.test.ts +++ b/src/vs/editor/test/common/viewModel/splitLinesCollection.test.ts @@ -109,9 +109,9 @@ suite('Editor ViewModel - SplitLinesCollection', () => { model, lineBreaksComputerFactory, lineBreaksComputerFactory, + fontInfo, model.getOptions().tabSize, wrappingInfo.wrappingColumn, - fontInfo.typicalFullwidthCharacterWidth / fontInfo.typicalHalfwidthCharacterWidth, wrappingIndent ); @@ -750,9 +750,9 @@ suite('SplitLinesCollection', () => { model, lineBreaksComputerFactory, lineBreaksComputerFactory, + fontInfo, model.getOptions().tabSize, wrappingInfo.wrappingColumn, - fontInfo.typicalFullwidthCharacterWidth / fontInfo.typicalHalfwidthCharacterWidth, wrappingIndent );