提交 12396ea0 编写于 作者: A Alex Dima

Fixes #40271: Compute visible line widths when restoring the scroll position

上级 d7f82bdc
......@@ -450,6 +450,13 @@ export class View extends ViewEventHandler {
this._scrollbar.delegateVerticalScrollbarMouseDown(browserEvent);
}
public restoreState(scrollPosition: { scrollLeft: number; scrollTop: number; }): void {
this._context.viewLayout.setScrollPositionNow({ scrollTop: scrollPosition.scrollTop });
this._renderNow();
this.viewLines.updateLineWidths();
this._context.viewLayout.setScrollPositionNow({ scrollLeft: scrollPosition.scrollLeft });
}
public getOffsetForColumn(modelLineNumber: number, modelColumn: number): number {
let modelPosition = this._context.model.validateModelPosition({
lineNumber: modelLineNumber,
......
......@@ -455,6 +455,10 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost<ViewLine>,
// --- implementation
public updateLineWidths(): void {
this._updateLineWidths(false);
}
/**
* Updates the max line width if it is fast to compute.
* Returns true if all lines were taken into account.
......
......@@ -392,6 +392,16 @@ export abstract class CodeEditorWidget extends CommonCodeEditor implements edito
viewEventBus.onKeyDown = (e) => this._onKeyDown.fire(e);
}
public restoreViewState(s: editorCommon.ICodeEditorViewState): void {
super.restoreViewState(s);
if (!this.cursor || !this.hasView) {
return;
}
if (s && s.cursorState && s.viewState) {
this._view.restoreState(this.viewModel.viewLayout.reduceRestoreState(s.viewState));
}
}
protected _detachModel(): editorCommon.IModel {
let removeDomNode: HTMLElement = null;
......
......@@ -651,7 +651,6 @@ export abstract class CommonCodeEditor extends Disposable {
// Backwards compatibility
this.cursor.restoreState([<editorCommon.ICursorState>cursorState]);
}
this.viewModel.viewLayout.restoreState(codeEditorState.viewState);
let contributionsState = s.contributionsState || {};
let keys = Object.keys(this._contributions);
......
......@@ -175,15 +175,15 @@ export class ViewLayout extends Disposable implements IViewLayout {
};
}
public restoreState(state: editorCommon.IViewState): void {
public reduceRestoreState(state: editorCommon.IViewState): { scrollLeft: number; scrollTop: number; } {
let restoreScrollTop = state.scrollTop;
if (typeof state.scrollTopWithoutViewZones === 'number' && !this._linesLayout.hasWhitespace()) {
restoreScrollTop = state.scrollTopWithoutViewZones;
}
this.scrollable.setScrollPositionNow({
return {
scrollLeft: state.scrollLeft,
scrollTop: restoreScrollTop
});
};
}
// ---- IVerticalLayoutProvider
......
......@@ -63,7 +63,7 @@ export interface IViewLayout {
getWhitespaces(): IEditorWhitespace[];
saveState(): IViewState;
restoreState(state: IViewState): void;
reduceRestoreState(state: IViewState): { scrollLeft: number; scrollTop: number; };
isAfterLines(verticalOffset: number): boolean;
getLineNumberAtVerticalOffset(verticalOffset: number): number;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册