提交 ad605ea3 编写于 作者: A Alex Dima

Reduce IViewLayout usage

上级 5ab42104
......@@ -126,9 +126,9 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp
// - scrolling (i.e. viewport / full size) & co.
// - whitespaces (a.k.a. view zones) management & co.
// - line heights updating & co.
this.layoutProvider = new LayoutProvider(configuration, model, this.eventDispatcher);
this.layoutProvider = new LayoutProvider(configuration, model.getLineCount(), this.eventDispatcher);
this._scrollbar = new EditorScrollbar(this.layoutProvider.getScrollable(), configuration, this.eventDispatcher, this.linesContent, this.domNode, this.overflowGuardContainer);
this._scrollbar = new EditorScrollbar(this.layoutProvider.getScrollable(), configuration, this.linesContent, this.domNode, this.overflowGuardContainer);
// The view context is passed on to most classes (basically to reduce param. counts in ctors)
this._context = new ViewContext(
......@@ -236,22 +236,22 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp
let scrollDecoration = new ScrollDecorationViewPart(this._context);
this.viewParts.push(scrollDecoration);
let contentViewOverlays = new ContentViewOverlays(this._context, this.layoutProvider);
let contentViewOverlays = new ContentViewOverlays(this._context);
this.viewParts.push(contentViewOverlays);
contentViewOverlays.addDynamicOverlay(new CurrentLineHighlightOverlay(this._context, this.layoutProvider));
contentViewOverlays.addDynamicOverlay(new CurrentLineHighlightOverlay(this._context));
contentViewOverlays.addDynamicOverlay(new SelectionsOverlay(this._context));
contentViewOverlays.addDynamicOverlay(new DecorationsOverlay(this._context));
contentViewOverlays.addDynamicOverlay(new IndentGuidesOverlay(this._context));
let marginViewOverlays = new MarginViewOverlays(this._context, this.layoutProvider);
let marginViewOverlays = new MarginViewOverlays(this._context);
this.viewParts.push(marginViewOverlays);
marginViewOverlays.addDynamicOverlay(new CurrentLineMarginHighlightOverlay(this._context, this.layoutProvider));
marginViewOverlays.addDynamicOverlay(new CurrentLineMarginHighlightOverlay(this._context));
marginViewOverlays.addDynamicOverlay(new GlyphMarginOverlay(this._context));
marginViewOverlays.addDynamicOverlay(new MarginViewLineDecorationsOverlay(this._context));
marginViewOverlays.addDynamicOverlay(new LinesDecorationsOverlay(this._context));
marginViewOverlays.addDynamicOverlay(new LineNumbersOverlay(this._context));
let margin = new Margin(this._context, this.layoutProvider);
let margin = new Margin(this._context);
margin.domNode.appendChild(this.viewZones.marginDomNode);
margin.domNode.appendChild(marginViewOverlays.getDomNode());
this.viewParts.push(margin);
......@@ -267,7 +267,7 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp
this.overlayWidgets = new ViewOverlayWidgets(this._context);
this.viewParts.push(this.overlayWidgets);
let rulers = new Rulers(this._context, this.layoutProvider);
let rulers = new Rulers(this._context);
this.viewParts.push(rulers);
// -------------- Wire dom nodes up
......@@ -448,7 +448,7 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp
// --- begin event handlers
public onModelFlushed(): boolean {
this.layoutProvider.onModelFlushed();
this.layoutProvider.onModelFlushed(this._context.model.getLineCount());
return false;
}
public onModelLinesDeleted(e: editorCommon.IViewLinesDeletedEvent): boolean {
......
......@@ -12,21 +12,18 @@ import { DynamicViewOverlay } from 'vs/editor/browser/view/dynamicViewOverlay';
import { Configuration } from 'vs/editor/browser/config/configuration';
import { ViewContext } from 'vs/editor/common/view/viewContext';
import { IRenderingContext, IRestrictedRenderingContext } from 'vs/editor/common/view/renderingContext';
import { IViewLayout } from 'vs/editor/common/viewModel/viewModel';
import { ViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData';
export class ViewOverlays extends ViewLayer<ViewOverlayLine> {
private _dynamicOverlays: DynamicViewOverlay[];
private _isFocused: boolean;
protected _viewLayout: IViewLayout;
constructor(context: ViewContext, viewLayout: IViewLayout) {
constructor(context: ViewContext) {
super(context);
this._dynamicOverlays = [];
this._isFocused = false;
this._viewLayout = viewLayout;
this.domNode.setClassName('view-overlays');
}
......@@ -48,7 +45,6 @@ export class ViewOverlays extends ViewLayer<ViewOverlayLine> {
public dispose(): void {
super.dispose();
this._viewLayout = null;
for (let i = 0, len = this._dynamicOverlays.length; i < len; i++) {
let dynamicOverlay = this._dynamicOverlays[i];
......@@ -180,16 +176,13 @@ export class ViewOverlayLine implements IVisibleLine {
export class ContentViewOverlays extends ViewOverlays {
private _scrollWidth: number;
private _contentWidth: number;
constructor(context: ViewContext, viewLayout: IViewLayout) {
super(context, viewLayout);
constructor(context: ViewContext) {
super(context);
this._scrollWidth = this._viewLayout.getScrollWidth();
this._contentWidth = this._context.configuration.editor.layoutInfo.contentWidth;
this.domNode.setWidth(this._scrollWidth);
this.domNode.setHeight(0);
}
......@@ -200,14 +193,13 @@ export class ContentViewOverlays extends ViewOverlays {
return super.onConfigurationChanged(e);
}
public onScrollChanged(e: IScrollEvent): boolean {
this._scrollWidth = e.scrollWidth;
return super.onScrollChanged(e) || e.scrollWidthChanged;
}
_viewOverlaysRender(ctx: IRestrictedRenderingContext): void {
super._viewOverlaysRender(ctx);
this.domNode.setWidth(Math.max(this._scrollWidth, this._contentWidth));
this.domNode.setWidth(Math.max(ctx.scrollWidth, this._contentWidth));
}
}
......@@ -216,8 +208,8 @@ export class MarginViewOverlays extends ViewOverlays {
private _contentLeft: number;
private _canUseTranslate3d: boolean;
constructor(context: ViewContext, viewLayout: IViewLayout) {
super(context, viewLayout);
constructor(context: ViewContext) {
super(context);
this._contentLeft = context.configuration.editor.layoutInfo.contentLeft;
this._canUseTranslate3d = context.configuration.editor.viewInfo.canUseTranslate3d;
......@@ -250,7 +242,7 @@ export class MarginViewOverlays extends ViewOverlays {
_viewOverlaysRender(ctx: IRestrictedRenderingContext): void {
super._viewOverlaysRender(ctx);
let height = Math.min(this._viewLayout.getTotalHeight(), 1000000);
let height = Math.min(ctx.scrollHeight, 1000000);
this.domNode.setHeight(height);
this.domNode.setWidth(this._contentLeft);
}
......
......@@ -4,47 +4,44 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { Scrollable, ScrollbarVisibility } from 'vs/base/common/scrollable';
import { Disposable } from 'vs/base/common/lifecycle';
import { Scrollable, ScrollState, ScrollEvent, ScrollbarVisibility } from 'vs/base/common/scrollable';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { LinesLayout } from 'vs/editor/common/viewLayout/linesLayout';
import { IViewLayout, IViewModel } from 'vs/editor/common/viewModel/viewModel';
import { IViewLayout } from 'vs/editor/common/viewModel/viewModel';
import { IPartialViewLinesViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData';
import { IViewEventBus } from 'vs/editor/common/view/viewContext';
export class LayoutProvider implements IDisposable, IViewLayout {
export class LayoutProvider extends Disposable implements IViewLayout {
static LINES_HORIZONTAL_EXTRA_PX = 30;
private _toDispose: IDisposable[];
private _configuration: editorCommon.IConfiguration;
private _privateViewEventBus: IViewEventBus;
private _model: IViewModel;
private _linesLayout: LinesLayout;
private _scrollable: Scrollable;
constructor(configuration: editorCommon.IConfiguration, model: IViewModel, privateViewEventBus: IViewEventBus) {
this._scrollable = new Scrollable();
this._scrollable.updateState({
width: configuration.editor.layoutInfo.contentWidth,
height: configuration.editor.layoutInfo.contentHeight
});
this._toDispose = [];
this._toDispose.push(this._scrollable);
constructor(configuration: editorCommon.IConfiguration, lineCount: number, privateViewEventBus: IViewEventBus) {
super();
this._configuration = configuration;
this._privateViewEventBus = privateViewEventBus;
this._model = model;
this._configuration.setMaxLineNumber(this._model.getMaxLineNumber());
this._linesLayout = new LinesLayout(lineCount, this._configuration.editor.lineHeight);
this._linesLayout = new LinesLayout(this._model.getLineCount(), this._configuration.editor.lineHeight);
this._scrollable = this._register(new Scrollable());
this._scrollable.updateState({
width: configuration.editor.layoutInfo.contentWidth,
height: configuration.editor.layoutInfo.contentHeight
});
this._register(this._scrollable.onScroll((e: ScrollEvent) => {
this._privateViewEventBus.emit(editorCommon.EventType.ViewScrollChanged, e);
}));
this._updateHeight();
}
public dispose(): void {
this._toDispose = dispose(this._toDispose);
super.dispose();
}
public getScrollable(): Scrollable {
......@@ -57,21 +54,18 @@ export class LayoutProvider implements IDisposable, IViewLayout {
// ---- begin view event handlers
public onModelFlushed(): void {
this._linesLayout.onModelFlushed(this._model.getLineCount());
this._configuration.setMaxLineNumber(this._model.getMaxLineNumber());
public onModelFlushed(lineCount: number): void {
this._linesLayout.onModelFlushed(lineCount);
this._updateHeight();
}
public onModelLinesDeleted(e: editorCommon.IViewLinesDeletedEvent): void {
this._linesLayout.onModelLinesDeleted(e.fromLineNumber, e.toLineNumber);
this._configuration.setMaxLineNumber(this._model.getMaxLineNumber());
this._updateHeight();
}
public onModelLinesInserted(e: editorCommon.IViewLinesInsertedEvent): void {
this._linesLayout.onModelLinesInserted(e.fromLineNumber, e.toLineNumber);
this._configuration.setMaxLineNumber(this._model.getMaxLineNumber());
this._updateHeight();
}
......@@ -89,14 +83,39 @@ export class LayoutProvider implements IDisposable, IViewLayout {
this._updateHeight();
}
// ---- end view event handlers
private _getHorizontalScrollbarHeight(scrollState: ScrollState): number {
if (this._configuration.editor.viewInfo.scrollbar.horizontal === ScrollbarVisibility.Hidden) {
// horizontal scrollbar not visible
return 0;
}
if (scrollState.width <= scrollState.scrollWidth) {
// horizontal scrollbar not visible
return 0;
}
return this._configuration.editor.viewInfo.scrollbar.horizontalScrollbarSize;
}
private _getTotalHeight(): number {
const scrollState = this._scrollable.getState();
let result = this._linesLayout.getLinesTotalHeight();
if (this._configuration.editor.viewInfo.scrollBeyondLastLine) {
result += scrollState.height - this._configuration.editor.lineHeight;
} else {
result += this._getHorizontalScrollbarHeight(scrollState);
}
return Math.max(scrollState.height, result);
}
private _updateHeight(): void {
this._scrollable.updateState({
scrollHeight: this.getTotalHeight()
scrollHeight: this._getTotalHeight()
});
}
// ---- end view event handlers
// ---- Layouting logic
public getCurrentViewport(): editorCommon.Viewport {
......@@ -181,37 +200,6 @@ export class LayoutProvider implements IDisposable, IViewLayout {
return this._linesLayout.getLineNumberAtOrAfterVerticalOffset(verticalOffset);
}
/**
* Get the sum of heights for all objects and compute basically the `scrollHeight` for the editor content.
*
* Take into account the `scrollBeyondLastLine` and `reserveHorizontalScrollbarHeight` and produce a scrollHeight that is at least as large as `viewport`.height.
*
* @param viewport The viewport.
* @param reserveHorizontalScrollbarHeight The height of the horizontal scrollbar.
* @return Basically, the `scrollHeight` for the editor content.
*/
private _getTotalHeight(viewport: editorCommon.Viewport, reserveHorizontalScrollbarHeight: number): number {
var totalLinesHeight = this._linesLayout.getLinesTotalHeight();
if (this._configuration.editor.viewInfo.scrollBeyondLastLine) {
totalLinesHeight += viewport.height - this._configuration.editor.lineHeight;
} else {
totalLinesHeight += reserveHorizontalScrollbarHeight;
}
return Math.max(viewport.height, totalLinesHeight);
}
public getTotalHeight(): number {
const scrollState = this._scrollable.getState();
let reserveHorizontalScrollbarHeight = 0;
if (scrollState.scrollWidth > scrollState.width) {
if (this._configuration.editor.viewInfo.scrollbar.horizontal !== ScrollbarVisibility.Hidden) {
reserveHorizontalScrollbarHeight = this._configuration.editor.viewInfo.scrollbar.horizontalScrollbarSize;
}
}
return this._getTotalHeight(this.getCurrentViewport(), reserveHorizontalScrollbarHeight);
}
public getWhitespaceAtVerticalOffset(verticalOffset: number): editorCommon.IViewWhitespaceViewportData {
return this._linesLayout.getWhitespaceAtVerticalOffset(verticalOffset);
}
......
......@@ -10,33 +10,29 @@ import * as editorCommon from 'vs/editor/common/editorCommon';
import { DynamicViewOverlay } from 'vs/editor/browser/view/dynamicViewOverlay';
import { ViewContext } from 'vs/editor/common/view/viewContext';
import { IRenderingContext } from 'vs/editor/common/view/renderingContext';
import { IViewLayout } from 'vs/editor/common/viewModel/viewModel';
export class CurrentLineHighlightOverlay extends DynamicViewOverlay {
private _context: ViewContext;
private _lineHeight: number;
private _readOnly: boolean;
private _renderLineHighlight: 'none' | 'gutter' | 'line' | 'all';
private _viewLayout: IViewLayout;
private _selectionIsEmpty: boolean;
private _primaryCursorIsInEditableRange: boolean;
private _primaryCursorLineNumber: number;
private _scrollWidth: number;
private _contentWidth: number;
constructor(context: ViewContext, viewLayout: IViewLayout) {
constructor(context: ViewContext) {
super();
this._context = context;
this._lineHeight = this._context.configuration.editor.lineHeight;
this._readOnly = this._context.configuration.editor.readOnly;
this._renderLineHighlight = this._context.configuration.editor.viewInfo.renderLineHighlight;
this._viewLayout = viewLayout;
this._selectionIsEmpty = true;
this._primaryCursorIsInEditableRange = true;
this._primaryCursorLineNumber = 1;
this._scrollWidth = this._viewLayout.getScrollWidth();
this._scrollWidth = 0;
this._contentWidth = this._context.configuration.editor.layoutInfo.contentWidth;
this._context.addEventHandler(this);
......@@ -53,7 +49,6 @@ export class CurrentLineHighlightOverlay extends DynamicViewOverlay {
this._primaryCursorIsInEditableRange = true;
this._selectionIsEmpty = true;
this._primaryCursorLineNumber = 1;
this._scrollWidth = this._viewLayout.getScrollWidth();
return true;
}
public onModelLinesDeleted(e: editorCommon.IViewLinesDeletedEvent): boolean {
......@@ -101,7 +96,6 @@ export class CurrentLineHighlightOverlay extends DynamicViewOverlay {
return true;
}
public onScrollChanged(e: editorCommon.IScrollEvent): boolean {
this._scrollWidth = e.scrollWidth;
return e.scrollWidthChanged;
}
public onZonesChanged(): boolean {
......
......@@ -10,25 +10,21 @@ import * as editorCommon from 'vs/editor/common/editorCommon';
import { DynamicViewOverlay } from 'vs/editor/browser/view/dynamicViewOverlay';
import { ViewContext } from 'vs/editor/common/view/viewContext';
import { IRenderingContext } from 'vs/editor/common/view/renderingContext';
import { IViewLayout } from 'vs/editor/common/viewModel/viewModel';
export class CurrentLineMarginHighlightOverlay extends DynamicViewOverlay {
private _context: ViewContext;
private _lineHeight: number;
private _renderLineHighlight: 'none' | 'gutter' | 'line' | 'all';
private _viewLayout: IViewLayout;
private _primaryCursorIsInEditableRange: boolean;
private _primaryCursorLineNumber: number;
private _contentLeft: number;
constructor(context: ViewContext, viewLayout: IViewLayout) {
constructor(context: ViewContext) {
super();
this._context = context;
this._lineHeight = this._context.configuration.editor.lineHeight;
this._renderLineHighlight = this._context.configuration.editor.viewInfo.renderLineHighlight;
this._viewLayout = viewLayout;
this._primaryCursorIsInEditableRange = true;
this._primaryCursorLineNumber = 1;
this._contentLeft = this._context.configuration.editor.layoutInfo.contentLeft;
......
......@@ -8,9 +8,8 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import * as dom from 'vs/base/browser/dom';
import { ScrollableElementCreationOptions, ScrollableElementChangeOptions } from 'vs/base/browser/ui/scrollbar/scrollableElementOptions';
import { IOverviewRulerLayoutInfo, ScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement';
import { EventType, IConfiguration, IConfigurationChangedEvent, IScrollEvent, INewScrollPosition } from 'vs/editor/common/editorCommon';
import { IConfiguration, IConfigurationChangedEvent, INewScrollPosition } from 'vs/editor/common/editorCommon';
import { ClassNames } from 'vs/editor/browser/editorBrowser';
import { IViewEventBus } from 'vs/editor/common/view/viewContext';
import { PartFingerprint, PartFingerprints } from 'vs/editor/browser/view/viewPart';
import { Scrollable } from 'vs/base/common/scrollable';
......@@ -24,17 +23,15 @@ export class EditorScrollbar implements IDisposable {
private scrollable: Scrollable;
private configuration: IConfiguration;
private privateViewEventBus: IViewEventBus;
private toDispose: IDisposable[];
private linesContent: HTMLElement;
private scrollbar: ScrollableElement;
constructor(scrollable: Scrollable, configuration: IConfiguration, privateViewEventBus: IViewEventBus, linesContent: HTMLElement, viewDomNode: HTMLElement, overflowGuardDomNode: HTMLElement) {
constructor(scrollable: Scrollable, configuration: IConfiguration, linesContent: HTMLElement, viewDomNode: HTMLElement, overflowGuardDomNode: HTMLElement) {
this.toDispose = [];
this.scrollable = scrollable;
this.configuration = configuration;
this.privateViewEventBus = privateViewEventBus;
this.linesContent = linesContent;
let configScrollbarOpts = this.configuration.editor.viewInfo.scrollbar;
......@@ -63,9 +60,6 @@ export class EditorScrollbar implements IDisposable {
PartFingerprints.write(this.scrollbar.getDomNode(), PartFingerprint.ScrollableElement);
this.toDispose.push(this.scrollbar);
this.toDispose.push(this.scrollbar.onScroll((e: IScrollEvent) => {
this.privateViewEventBus.emit(EventType.ViewScrollChanged, e);
}));
this.toDispose.push(this.configuration.onDidChange((e: IConfigurationChangedEvent) => {
this.scrollbar.updateClassName(ClassNames.SCROLLABLE_ELEMENT + ' ' + this.configuration.editor.viewInfo.theme);
......
......@@ -421,7 +421,7 @@ export class ViewLines extends ViewLayer<ViewLine> implements IViewLines {
this._lastRenderedData.setBigNumbersDelta(viewportData.bigNumbersDelta);
this._lastRenderedData.setCurrentVisibleRange(viewportData.visibleRange);
this.domNode.setWidth(this._viewLayout.getScrollWidth());
this.domNode.setHeight(Math.min(this._viewLayout.getTotalHeight(), 1000000));
this.domNode.setHeight(Math.min(this._viewLayout.getScrollHeight(), 1000000));
// (2) execute DOM writing that forces sync layout (e.g. textArea manipulation)
onAfterLinesRendered();
......
......@@ -11,20 +11,17 @@ import { ClassNames } from 'vs/editor/browser/editorBrowser';
import { ViewPart } from 'vs/editor/browser/view/viewPart';
import { ViewContext } from 'vs/editor/common/view/viewContext';
import { IRenderingContext, IRestrictedRenderingContext } from 'vs/editor/common/view/renderingContext';
import { IViewLayout } from 'vs/editor/common/viewModel/viewModel';
export class Margin extends ViewPart {
public domNode: HTMLElement;
private _viewLayout: IViewLayout;
private _canUseTranslate3d: boolean;
private _contentLeft: number;
private _glyphMarginLeft: number;
private _glyphMarginWidth: number;
private _glyphMarginBackgroundDomNode: FastDomNode;
constructor(context: ViewContext, viewLayout: IViewLayout) {
constructor(context: ViewContext) {
super(context);
this._viewLayout = viewLayout;
this._canUseTranslate3d = this._context.configuration.editor.viewInfo.canUseTranslate3d;
this._contentLeft = this._context.configuration.editor.layoutInfo.contentLeft;
this._glyphMarginLeft = this._context.configuration.editor.layoutInfo.glyphMarginLeft;
......@@ -89,7 +86,7 @@ export class Margin extends ViewPart {
StyleMutator.setTop(this.domNode, ctx.viewportData.visibleRangesDeltaTop);
}
let height = Math.min(this._viewLayout.getTotalHeight(), 1000000);
let height = Math.min(ctx.scrollHeight, 1000000);
StyleMutator.setHeight(this.domNode, height);
StyleMutator.setWidth(this.domNode, this._contentLeft);
......
......@@ -11,19 +11,16 @@ import * as editorCommon from 'vs/editor/common/editorCommon';
import { ViewPart } from 'vs/editor/browser/view/viewPart';
import { ViewContext } from 'vs/editor/common/view/viewContext';
import { IRenderingContext, IRestrictedRenderingContext } from 'vs/editor/common/view/renderingContext';
import { IViewLayout } from 'vs/editor/common/viewModel/viewModel';
export class Rulers extends ViewPart {
public domNode: HTMLElement;
private _viewLayout: IViewLayout;
private _rulers: number[];
private _height: number;
private _typicalHalfwidthCharacterWidth: number;
constructor(context: ViewContext, viewLayout: IViewLayout) {
constructor(context: ViewContext) {
super(context);
this._viewLayout = viewLayout;
this.domNode = document.createElement('div');
this.domNode.className = 'view-rulers';
this._rulers = this._context.configuration.editor.viewInfo.rulers;
......@@ -79,7 +76,7 @@ export class Rulers extends ViewPart {
this.domNode.appendChild(node);
}
StyleMutator.setHeight(node, Math.min(this._viewLayout.getTotalHeight(), 1000000));
StyleMutator.setHeight(node, Math.min(ctx.scrollHeight, 1000000));
StyleMutator.setLeft(node, this._rulers[i] * this._typicalHalfwidthCharacterWidth);
}
}
......
......@@ -531,6 +531,9 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed
}
public setMaxLineNumber(maxLineNumber: number): void {
if (this._maxLineNumber === maxLineNumber) {
return;
}
this._maxLineNumber = maxLineNumber;
this._recomputeOptions();
}
......
......@@ -10,7 +10,6 @@ import { ViewLineToken } from 'vs/editor/common/core/viewLineToken';
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 { Viewport } from 'vs/editor/common/editorCommon';
export interface IViewLayout {
......@@ -21,7 +20,6 @@ export interface IViewLayout {
getScrollHeight(): number;
getScrollTop(): number;
getCurrentViewport(): Viewport;
getTotalHeight(): number;
getScrolledTopFromAbsoluteTop(top: number): number;
getVerticalOffsetForLineNumber(lineNumber: number): number;
setScrollPosition(position: INewScrollPosition): void;
......@@ -82,10 +80,6 @@ export interface IViewModel extends IEventEmitter {
getLineMinColumn(lineNumber: number): number;
getLineMaxColumn(lineNumber: number): number;
getLineRenderLineNumber(lineNumber: number): string;
/**
* Get the maximum line number that will appear next to a line
*/
getMaxLineNumber(): number;
getAllOverviewRulerDecorations(): ViewModelDecoration[];
getEOL(): string;
getValueInRange(range: Range, eol: EndOfLinePreference): string;
......
......@@ -96,6 +96,7 @@ export class ViewModel extends EventEmitter implements IViewModel {
this.editorId = editorId;
this.configuration = configuration;
this.model = model;
this.configuration.setMaxLineNumber(this.model.getLineCount());
this.coordinatesConverter = new CoordinatesConverter(this.lines);
......@@ -235,6 +236,11 @@ export class ViewModel extends EventEmitter implements IViewModel {
private _onEvents(events: EmitterEvent[]): void {
const containsModelContentChangeEvent = ViewModel._containsModelContentChangeEvent(events);
if (containsModelContentChangeEvent) {
this.configuration.setMaxLineNumber(this.model.getLineCount());
}
// We might need to restore the current centered view range in the following circumstances:
// All of these changes might lead to a new line mapping:
// (a) model tabSize changed
......@@ -245,7 +251,7 @@ export class ViewModel extends EventEmitter implements IViewModel {
// because we cannot convert the view range to a model range.
let previousCenteredModelRange: Range = null;
if (!ViewModel._containsModelContentChangeEvent(events) && ViewModel._containsWrappingRelatedEvents(events)) {
if (!containsModelContentChangeEvent && ViewModel._containsWrappingRelatedEvents(events)) {
previousCenteredModelRange = this.getCenteredRangeInViewport();
}
......@@ -504,11 +510,6 @@ export class ViewModel extends EventEmitter implements IViewModel {
return String(modelLineNumber);
}
public getMaxLineNumber(): number {
// The largest value for a line number will be that of the model line count
return this.model.getLineCount();
}
public getDecorationsInViewport(visibleRange: Range): ViewModelDecoration[] {
return this.decorations.getDecorationsViewportData(visibleRange).decorations;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册