diff --git a/src/vs/editor/browser/view/viewImpl.ts b/src/vs/editor/browser/view/viewImpl.ts index bf5f76bbf5b7e3791a7af637cf7d8f26a834cb3d..57ac6405e1a8838c8445cf221a65cf7d5a06fda4 100644 --- a/src/vs/editor/browser/view/viewImpl.ts +++ b/src/vs/editor/browser/view/viewImpl.ts @@ -112,6 +112,9 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp // The event dispatcher will always go through _renderOnce before dispatching any events this.eventDispatcher = new ViewEventDispatcher((callback: () => void) => this._renderOnce(callback)); + // Ensure the view is the first event handler in order to update the layout + this.eventDispatcher.addEventHandler(this); + // The layout provider has such responsibilities as: // - scrolling (i.e. viewport / full size) & co. // - whitespaces (a.k.a. view zones) management & co. @@ -134,7 +137,6 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp this.hasFocus = false; this.codeEditorHelper = null; - this.eventDispatcher.addEventHandler(this); // The view lines rendering calls model.getLineTokens() that might emit events that its tokens have changed. // This delayed processing of incoming model events acts as a guard against undesired/unexpected recursion. diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index 4ee5af6d9b45dba06ad8c6be4072e5101c24a00f..9cb8ec7a7c252c758e1d80629fc6337bd429d06c 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -109,7 +109,7 @@ class InternalEditorOptionsHelper { fontInfo: FontInfo, editorClassName: string, isDominatedByLongLines: boolean, - maxLineNumber: number, + lineNumbersDigitCount: number, canUseTranslate3d: boolean, pixelRatio: number ): editorCommon.InternalEditorOptions { @@ -180,7 +180,7 @@ class InternalEditorOptionsHelper { lineHeight: fontInfo.lineHeight, showLineNumbers: renderLineNumbers, lineNumbersMinChars: lineNumbersMinChars, - maxLineNumber: maxLineNumber, + lineNumbersDigitCount: lineNumbersDigitCount, lineDecorationsWidth: lineDecorationsWidth, typicalHalfwidthCharacterWidth: fontInfo.typicalHalfwidthCharacterWidth, maxDigitWidth: fontInfo.maxDigitWidth, @@ -475,7 +475,7 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed protected _configWithDefaults: ConfigurationWithDefaults; protected _elementSizeObserver: IElementSizeObserver; private _isDominatedByLongLines: boolean; - private _maxLineNumber: number; + private _lineNumbersDigitCount: number; private _onDidChange = this._register(new Emitter()); public onDidChange: Event = this._onDidChange.event; @@ -485,7 +485,7 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed this._configWithDefaults = new ConfigurationWithDefaults(options); this._elementSizeObserver = elementSizeObserver; this._isDominatedByLongLines = false; - this._maxLineNumber = 1; + this._lineNumbersDigitCount = 1; this.editor = this._computeInternalOptions(); this.editorClone = this.editor.clone(); this._register(EditorZoom.onDidChangeZoomLevel(_ => this._recomputeOptions())); @@ -535,7 +535,7 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed this.readConfiguration(bareFontInfo), editorClassName, this._isDominatedByLongLines, - this._maxLineNumber, + this._lineNumbersDigitCount, canUseTranslate3d, this._getPixelRatio() ); @@ -552,13 +552,23 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed } public setMaxLineNumber(maxLineNumber: number): void { - if (this._maxLineNumber === maxLineNumber) { + let digitCount = CommonEditorConfiguration.digitCount(maxLineNumber); + if (this._lineNumbersDigitCount === digitCount) { return; } - this._maxLineNumber = maxLineNumber; + this._lineNumbersDigitCount = digitCount; this._recomputeOptions(); } + private static digitCount(n: number): number { + var r = 0; + while (n) { + n = Math.floor(n / 10); + r++; + } + return r ? r : 1; + } + protected abstract _getEditorClassName(theme: string, fontLigatures: boolean): string; protected abstract getOuterWidth(): number; diff --git a/src/vs/editor/common/viewLayout/editorLayoutProvider.ts b/src/vs/editor/common/viewLayout/editorLayoutProvider.ts index 8679789fc080ac9d7a636e09b026f161a3664524..033fb70539ddc2165277c8a66977e540d5728d3b 100644 --- a/src/vs/editor/common/viewLayout/editorLayoutProvider.ts +++ b/src/vs/editor/common/viewLayout/editorLayoutProvider.ts @@ -15,7 +15,7 @@ export interface IEditorLayoutProviderOpts { showLineNumbers: boolean; lineNumbersMinChars: number; - maxLineNumber: number; + lineNumbersDigitCount: number; lineDecorationsWidth: number; @@ -39,7 +39,7 @@ export class EditorLayoutProvider { const lineHeight = _opts.lineHeight | 0; const showLineNumbers = Boolean(_opts.showLineNumbers); const lineNumbersMinChars = _opts.lineNumbersMinChars | 0; - const maxLineNumber = _opts.maxLineNumber | 0; + const lineNumbersDigitCount = _opts.lineNumbersDigitCount | 0; const lineDecorationsWidth = _opts.lineDecorationsWidth | 0; const typicalHalfwidthCharacterWidth = Number(_opts.typicalHalfwidthCharacterWidth); const maxDigitWidth = Number(_opts.maxDigitWidth); @@ -52,7 +52,7 @@ export class EditorLayoutProvider { let lineNumbersWidth = 0; if (showLineNumbers) { - let digitCount = Math.max(this.digitCount(maxLineNumber), lineNumbersMinChars); + let digitCount = Math.max(lineNumbersDigitCount, lineNumbersMinChars); lineNumbersWidth = Math.round(digitCount * maxDigitWidth); } @@ -142,12 +142,5 @@ export class EditorLayoutProvider { }); } - private static digitCount(n: number): number { - var r = 0; - while (n) { - n = Math.floor(n / 10); - r++; - } - return r ? r : 1; - } + } diff --git a/src/vs/editor/test/common/viewLayout/editorLayoutProvider.test.ts b/src/vs/editor/test/common/viewLayout/editorLayoutProvider.test.ts index 5f9b826150c6d883e2027ccc79f2fc4e89f23502..3e67f31cfe89bebe836c7e86cecc03c4ad64abb2 100644 --- a/src/vs/editor/test/common/viewLayout/editorLayoutProvider.test.ts +++ b/src/vs/editor/test/common/viewLayout/editorLayoutProvider.test.ts @@ -23,7 +23,7 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => { lineHeight: 16, showLineNumbers: false, lineNumbersMinChars: 0, - maxLineNumber: 1, + lineNumbersDigitCount: 1, lineDecorationsWidth: 10, typicalHalfwidthCharacterWidth: 10, maxDigitWidth: 10, @@ -77,7 +77,7 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => { lineHeight: 16, showLineNumbers: false, lineNumbersMinChars: 0, - maxLineNumber: 1, + lineNumbersDigitCount: 1, lineDecorationsWidth: 10, typicalHalfwidthCharacterWidth: 10, maxDigitWidth: 10, @@ -131,7 +131,7 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => { lineHeight: 16, showLineNumbers: false, lineNumbersMinChars: 0, - maxLineNumber: 1, + lineNumbersDigitCount: 1, lineDecorationsWidth: 10, typicalHalfwidthCharacterWidth: 10, maxDigitWidth: 10, @@ -185,7 +185,7 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => { lineHeight: 16, showLineNumbers: false, lineNumbersMinChars: 0, - maxLineNumber: 1, + lineNumbersDigitCount: 1, lineDecorationsWidth: 10, typicalHalfwidthCharacterWidth: 10, maxDigitWidth: 10, @@ -239,7 +239,7 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => { lineHeight: 16, showLineNumbers: false, lineNumbersMinChars: 5, - maxLineNumber: 1, + lineNumbersDigitCount: 1, lineDecorationsWidth: 10, typicalHalfwidthCharacterWidth: 10, maxDigitWidth: 10, @@ -293,7 +293,7 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => { lineHeight: 16, showLineNumbers: true, lineNumbersMinChars: 5, - maxLineNumber: 1, + lineNumbersDigitCount: 1, lineDecorationsWidth: 10, typicalHalfwidthCharacterWidth: 10, maxDigitWidth: 10, @@ -347,7 +347,7 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => { lineHeight: 16, showLineNumbers: true, lineNumbersMinChars: 5, - maxLineNumber: 99999, + lineNumbersDigitCount: 5, lineDecorationsWidth: 10, typicalHalfwidthCharacterWidth: 10, maxDigitWidth: 10, @@ -401,7 +401,7 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => { lineHeight: 16, showLineNumbers: true, lineNumbersMinChars: 5, - maxLineNumber: 100000, + lineNumbersDigitCount: 6, lineDecorationsWidth: 10, typicalHalfwidthCharacterWidth: 10, maxDigitWidth: 10, @@ -455,7 +455,7 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => { lineHeight: 16, showLineNumbers: true, lineNumbersMinChars: 5, - maxLineNumber: 100000, + lineNumbersDigitCount: 6, lineDecorationsWidth: 10, typicalHalfwidthCharacterWidth: 5, maxDigitWidth: 5, @@ -509,7 +509,7 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => { lineHeight: 16, showLineNumbers: true, lineNumbersMinChars: 5, - maxLineNumber: 100000, + lineNumbersDigitCount: 6, lineDecorationsWidth: 10, typicalHalfwidthCharacterWidth: 5.05, maxDigitWidth: 5.05, @@ -563,7 +563,7 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => { lineHeight: 16, showLineNumbers: false, lineNumbersMinChars: 0, - maxLineNumber: 1, + lineNumbersDigitCount: 1, lineDecorationsWidth: 10, typicalHalfwidthCharacterWidth: 10, maxDigitWidth: 10, @@ -617,7 +617,7 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => { lineHeight: 16, showLineNumbers: false, lineNumbersMinChars: 0, - maxLineNumber: 1, + lineNumbersDigitCount: 1, lineDecorationsWidth: 10, typicalHalfwidthCharacterWidth: 10, maxDigitWidth: 10, @@ -671,7 +671,7 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => { lineHeight: 16, showLineNumbers: false, lineNumbersMinChars: 0, - maxLineNumber: 1, + lineNumbersDigitCount: 1, lineDecorationsWidth: 10, typicalHalfwidthCharacterWidth: 10, maxDigitWidth: 10,