Pass in entire fontInfo when computing line breaks

上级 314d0e12
......@@ -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);
}
};
}
......
......@@ -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)
);
......
......@@ -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];
......
......@@ -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;
}
......
......@@ -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());
......
......@@ -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];
......
......@@ -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
);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册