未验证 提交 a7c698ce 编写于 作者: A Alex Dima

Move view layout modification through view model

上级 4bb364cc
......@@ -100,7 +100,7 @@ class StandardPointerHandler extends MouseHandler implements IDisposable {
}
private _onGestureChange(e: IThrottledGestureEvent): void {
this._context.viewLayout.deltaScrollNow(-e.translationX, -e.translationY);
this._context.model.deltaScrollNow(-e.translationX, -e.translationY);
}
public dispose(): void {
......@@ -177,7 +177,7 @@ export class PointerEventHandler extends MouseHandler {
private onChange(e: GestureEvent): void {
if (this._lastPointerType === 'touch') {
this._context.viewLayout.deltaScrollNow(-e.translationX, -e.translationY);
this._context.model.deltaScrollNow(-e.translationX, -e.translationY);
}
}
......@@ -215,7 +215,7 @@ class TouchHandler extends MouseHandler {
}
private onChange(e: GestureEvent): void {
this._context.viewLayout.deltaScrollNow(-e.translationX, -e.translationY);
this._context.model.deltaScrollNow(-e.translationX, -e.translationY);
}
}
......
......@@ -443,11 +443,11 @@ export class View extends ViewEventHandler {
}
public restoreState(scrollPosition: { scrollLeft: number; scrollTop: number; }): void {
this._context.viewLayout.setScrollPosition({ scrollTop: scrollPosition.scrollTop }, ScrollType.Immediate);
this._context.model.setScrollPosition({ scrollTop: scrollPosition.scrollTop }, ScrollType.Immediate);
this._context.model.tokenizeViewport();
this._renderNow();
this.viewLines.updateLineWidths();
this._context.viewLayout.setScrollPosition({ scrollLeft: scrollPosition.scrollLeft }, ScrollType.Immediate);
this._context.model.setScrollPosition({ scrollLeft: scrollPosition.scrollLeft }, ScrollType.Immediate);
}
public getOffsetForColumn(modelLineNumber: number, modelColumn: number): number {
......@@ -480,7 +480,6 @@ export class View extends ViewEventHandler {
return this._renderOnce(() => {
const zonesHaveChanged = this.viewZones.changeViewZones(callback);
if (zonesHaveChanged) {
this._context.viewLayout.onHeightMaybeChanged();
this._context.privateViewEventBus.emit(new viewEvents.ViewZonesChangedEvent());
}
return zonesHaveChanged;
......
......@@ -88,7 +88,7 @@ export class EditorScrollbar extends ViewPart {
}
}
this._context.viewLayout.setScrollPosition(newScrollPosition, ScrollType.Immediate);
this._context.model.setScrollPosition(newScrollPosition, ScrollType.Immediate);
};
// I've seen this happen both on the view dom node & on the lines content dom node.
......
......@@ -282,7 +282,7 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost<ViewLine>,
const scrollTopDelta = Math.abs(this._context.viewLayout.getCurrentScrollTop() - newScrollPosition.scrollTop);
const scrollType = (scrollTopDelta <= this._lineHeight ? ScrollType.Immediate : e.scrollType);
this._context.viewLayout.setScrollPosition(newScrollPosition, scrollType);
this._context.model.setScrollPosition(newScrollPosition, scrollType);
return true;
}
......@@ -307,7 +307,7 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost<ViewLine>,
return this._visibleLines.onTokensChanged(e);
}
public onZonesChanged(e: viewEvents.ViewZonesChangedEvent): boolean {
this._context.viewLayout.onMaxLineWidthChanged(this._maxLineWidth);
this._context.model.setMaxLineWidth(this._maxLineWidth);
return this._visibleLines.onZonesChanged(e);
}
public onThemeChanged(e: viewEvents.ViewThemeChangedEvent): boolean {
......@@ -587,7 +587,7 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost<ViewLine>,
this._ensureMaxLineWidth(newScrollLeft.maxHorizontalOffset);
}
// set `scrollLeft`
this._context.viewLayout.setScrollPosition({
this._context.model.setScrollPosition({
scrollLeft: newScrollLeft.scrollLeft
}, horizontalRevealRequest.scrollType);
}
......@@ -626,7 +626,7 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost<ViewLine>,
const iLineWidth = Math.ceil(lineWidth);
if (this._maxLineWidth < iLineWidth) {
this._maxLineWidth = iLineWidth;
this._context.viewLayout.onMaxLineWidthChanged(this._maxLineWidth);
this._context.model.setMaxLineWidth(this._maxLineWidth);
}
}
......
......@@ -1022,7 +1022,7 @@ export class Minimap extends ViewPart implements IMinimapModel {
}
public setScrollTop(scrollTop: number): void {
this._context.viewLayout.setScrollPosition({
this._context.model.setScrollPosition({
scrollTop: scrollTop
}, ScrollType.Immediate);
}
......
......@@ -79,9 +79,8 @@ export class ViewZones extends ViewPart {
for (const whitespace of whitespaces) {
oldWhitespaces.set(whitespace.id, whitespace);
}
return this._context.viewLayout.changeWhitespace((whitespaceAccessor: IWhitespaceChangeAccessor) => {
let hadAChange = false;
let hadAChange = false;
this._context.model.changeWhitespace((whitespaceAccessor: IWhitespaceChangeAccessor) => {
const keys = Object.keys(this._zones);
for (let i = 0, len = keys.length; i < len; i++) {
const id = keys[i];
......@@ -94,9 +93,8 @@ export class ViewZones extends ViewPart {
hadAChange = true;
}
}
return hadAChange;
});
return hadAChange;
}
public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean {
......@@ -115,11 +113,7 @@ export class ViewZones extends ViewPart {
}
public onLineMappingChanged(e: viewEvents.ViewLineMappingChangedEvent): boolean {
const hadAChange = this._recomputeWhitespacesProps();
if (hadAChange) {
this._context.viewLayout.onHeightMaybeChanged();
}
return hadAChange;
return this._recomputeWhitespacesProps();
}
public onLinesDeleted(e: viewEvents.ViewLinesDeletedEvent): boolean {
......@@ -199,9 +193,9 @@ export class ViewZones extends ViewPart {
}
public changeViewZones(callback: (changeAccessor: IViewZoneChangeAccessor) => any): boolean {
let zonesHaveChanged = false;
return this._context.viewLayout.changeWhitespace((whitespaceAccessor: IWhitespaceChangeAccessor) => {
let zonesHaveChanged = false;
this._context.model.changeWhitespace((whitespaceAccessor: IWhitespaceChangeAccessor) => {
const changeAccessor: IViewZoneChangeAccessor = {
addZone: (zone: IViewZone): string => {
......@@ -231,6 +225,8 @@ export class ViewZones extends ViewPart {
return zonesHaveChanged;
});
return zonesHaveChanged;
}
private _addZone(whitespaceAccessor: IWhitespaceChangeAccessor, zone: IViewZone): string {
......
......@@ -862,7 +862,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
if (typeof newScrollLeft !== 'number') {
throw new Error('Invalid arguments');
}
this._modelData.viewModel.viewLayout.setScrollPosition({
this._modelData.viewModel.setScrollPosition({
scrollLeft: newScrollLeft
}, scrollType);
}
......@@ -873,7 +873,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
if (typeof newScrollTop !== 'number') {
throw new Error('Invalid arguments');
}
this._modelData.viewModel.viewLayout.setScrollPosition({
this._modelData.viewModel.setScrollPosition({
scrollTop: newScrollTop
}, scrollType);
}
......@@ -881,7 +881,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
if (!this._modelData) {
return;
}
this._modelData.viewModel.viewLayout.setScrollPosition(position, scrollType);
this._modelData.viewModel.setScrollPosition(position, scrollType);
}
public saveViewState(): editorCommon.ICodeEditorViewState | null {
......
......@@ -180,33 +180,36 @@ export class LinesLayout {
this._lineCount = lineCount;
}
public changeWhitespace<T>(callback: (accessor: IWhitespaceChangeAccessor) => T): T {
public changeWhitespace(callback: (accessor: IWhitespaceChangeAccessor) => void): boolean {
let hadAChange = false;
try {
const accessor = {
const accessor: IWhitespaceChangeAccessor = {
insertWhitespace: (afterLineNumber: number, ordinal: number, heightInPx: number, minWidth: number): string => {
hadAChange = true;
afterLineNumber = afterLineNumber | 0;
ordinal = ordinal | 0;
heightInPx = heightInPx | 0;
minWidth = minWidth | 0;
const id = this._instanceId + (++this._lastWhitespaceId);
this._pendingChanges.insert(new EditorWhitespace(id, afterLineNumber, ordinal, heightInPx, minWidth));
return id;
},
changeOneWhitespace: (id: string, newAfterLineNumber: number, newHeight: number): void => {
hadAChange = true;
newAfterLineNumber = newAfterLineNumber | 0;
newHeight = newHeight | 0;
this._pendingChanges.change({ id, newAfterLineNumber, newHeight });
},
removeWhitespace: (id: string): void => {
hadAChange = true;
this._pendingChanges.remove({ id });
}
};
return callback(accessor);
callback(accessor);
} finally {
this._pendingChanges.commit(this);
}
return hadAChange;
}
public _commitPendingChanges(inserts: EditorWhitespace[], changes: IPendingChange[], removes: IPendingRemove[]): void {
......
......@@ -324,7 +324,7 @@ export class ViewLayout extends Disposable implements IViewLayout {
}
}
public onMaxLineWidthChanged(maxLineWidth: number): void {
public setMaxLineWidth(maxLineWidth: number): void {
const scrollDimensions = this._scrollable.getScrollDimensions();
// const newScrollWidth = ;
this._scrollable.setScrollDimensions(new EditorScrollDimensions(
......@@ -353,8 +353,11 @@ export class ViewLayout extends Disposable implements IViewLayout {
}
// ---- IVerticalLayoutProvider
public changeWhitespace<T>(callback: (accessor: IWhitespaceChangeAccessor) => T): T {
return this._linesLayout.changeWhitespace(callback);
public changeWhitespace(callback: (accessor: IWhitespaceChangeAccessor) => void): void {
const hadAChange = this._linesLayout.changeWhitespace(callback);
if (hadAChange) {
this.onHeightMaybeChanged();
}
}
public getVerticalOffsetForLineNumber(lineNumber: number): number {
return this._linesLayout.getVerticalOffsetForLineNumber(lineNumber);
......
......@@ -44,8 +44,6 @@ export interface IViewLayout {
getScrollable(): Scrollable;
onMaxLineWidthChanged(width: number): void;
getScrollWidth(): number;
getScrollHeight(): number;
......@@ -56,8 +54,6 @@ export interface IViewLayout {
getFutureViewport(): Viewport;
validateScrollPosition(scrollPosition: INewScrollPosition): IScrollPosition;
setScrollPosition(position: INewScrollPosition, type: ScrollType): void;
deltaScrollNow(deltaScrollLeft: number, deltaScrollTop: number): void;
getLinesViewportData(): IPartialViewLinesViewportData;
getLinesViewportDataAtScrollTop(scrollTop: number): IPartialViewLinesViewportData;
......@@ -68,18 +64,10 @@ export interface IViewLayout {
getVerticalOffsetForLineNumber(lineNumber: number): number;
getWhitespaceAtVerticalOffset(verticalOffset: number): IViewWhitespaceViewportData | null;
// --------------- Begin vertical whitespace management
changeWhitespace<T>(callback: (accessor: IWhitespaceChangeAccessor) => T): T;
/**
* Get the layout information for whitespaces currently in the viewport
*/
getWhitespaceViewportData(): IViewWhitespaceViewportData[];
// TODO@Alex whitespace management should work via a change accessor sort of thing
onHeightMaybeChanged(): void;
// --------------- End vertical whitespace management
}
export interface ICoordinatesConverter {
......@@ -169,6 +157,10 @@ export interface IViewModel extends IViewEventEmitter, ICursorSimpleModel {
getVerticalOffsetForLineNumber(viewLineNumber: number): number;
getScrollTop(): number;
setScrollTop(newScrollTop: number, scrollType: ScrollType): void;
setScrollPosition(position: INewScrollPosition, type: ScrollType): void;
deltaScrollNow(deltaScrollLeft: number, deltaScrollTop: number): void;
changeWhitespace(callback: (accessor: IWhitespaceChangeAccessor) => void): void;
setMaxLineWidth(maxLineWidth: number): void;
//#endregion
}
......
......@@ -10,7 +10,7 @@ import { ConfigurationChangedEvent, EDITOR_FONT_DEFAULTS, EditorOption, filterVa
import { IPosition, Position } from 'vs/editor/common/core/position';
import { ISelection, Selection } from 'vs/editor/common/core/selection';
import { IRange, Range } from 'vs/editor/common/core/range';
import { IConfiguration, IViewState, ScrollType, ICursorState, ICommand } from 'vs/editor/common/editorCommon';
import { IConfiguration, IViewState, ScrollType, ICursorState, ICommand, INewScrollPosition } from 'vs/editor/common/editorCommon';
import { EndOfLinePreference, IActiveIndentGuideInfo, ITextModel, TrackedRangeStickiness, TextModelResolvedOptions, IIdentifiedSingleEditOperation, ICursorStateComputer } from 'vs/editor/common/model';
import { ModelDecorationOverviewRulerOptions, ModelDecorationMinimapOptions } from 'vs/editor/common/model/textModel';
import * as textModelEvents from 'vs/editor/common/model/textModelEvents';
......@@ -28,6 +28,7 @@ import { EditorTheme } from 'vs/editor/common/view/viewContext';
import { Cursor } from 'vs/editor/common/controller/cursor';
import { PartialCursorState, CursorState, IColumnSelectData, EditOperationType, CursorConfiguration } from 'vs/editor/common/controller/cursorCommon';
import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents';
import { IWhitespaceChangeAccessor } from 'vs/editor/common/viewLayout/linesLayout';
const USE_IDENTITY_LINES_COLLECTION = true;
......@@ -943,6 +944,18 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel
public setScrollTop(newScrollTop: number, scrollType: ScrollType): void {
this.viewLayout.setScrollPosition({ scrollTop: newScrollTop }, scrollType);
}
public setScrollPosition(position: INewScrollPosition, type: ScrollType): void {
this.viewLayout.setScrollPosition(position, type);
}
public deltaScrollNow(deltaScrollLeft: number, deltaScrollTop: number): void {
this.viewLayout.deltaScrollNow(deltaScrollLeft, deltaScrollTop);
}
public changeWhitespace(callback: (accessor: IWhitespaceChangeAccessor) => void): void {
return this.viewLayout.changeWhitespace(callback);
}
public setMaxLineWidth(maxLineWidth: number): void {
this.viewLayout.setMaxLineWidth(maxLineWidth);
}
//#endregion
private _withViewEventsCollector(callback: (eventsCollector: viewEvents.ViewEventsCollector) => void): void {
......
......@@ -8,9 +8,11 @@ import { LinesLayout, EditorWhitespace } from 'vs/editor/common/viewLayout/lines
suite('Editor ViewLayout - LinesLayout', () => {
function insertWhitespace(linesLayout: LinesLayout, afterLineNumber: number, ordinal: number, heightInPx: number, minWidth: number): string {
return linesLayout.changeWhitespace((accessor) => {
return accessor.insertWhitespace(afterLineNumber, ordinal, heightInPx, minWidth);
let id: string;
linesLayout.changeWhitespace((accessor) => {
id = accessor.insertWhitespace(afterLineNumber, ordinal, heightInPx, minWidth);
});
return id!;
}
function changeOneWhitespace(linesLayout: LinesLayout, id: string, newAfterLineNumber: number, newHeight: number): void {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册