Skip to content

Commit

Permalink
chore: more comments2
Browse files Browse the repository at this point in the history
  • Loading branch information
lumixraku committed Jun 1, 2024
1 parent 2ccbaea commit b17b616
Show file tree
Hide file tree
Showing 16 changed files with 127 additions and 146 deletions.
6 changes: 4 additions & 2 deletions packages/engine-render/src/basics/scroll-xy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
* limitations under the License.
*/

import type { Viewport } from '../viewport';

export function getCurrentScrollXY(scrollTimer: any) {
const scene = scrollTimer.getScene();
const viewport = scrollTimer.getViewportByCoord(scene);
const viewport = scrollTimer.getViewportByCoord(scene) as Viewport;
const scrollX = 0;
const scrollY = 0;
if (!viewport) {
Expand All @@ -25,7 +27,7 @@ export function getCurrentScrollXY(scrollTimer: any) {
scrollY,
};
}
const actualScroll = viewport.getActualScroll(viewport.scrollX, viewport.scrollY);
const actualScroll = viewport.transScroll2ViewportScrollValue(viewport.scrollX, viewport.scrollY);
return {
scrollX: actualScroll.x,
scrollY: actualScroll.y,
Expand Down
68 changes: 23 additions & 45 deletions packages/engine-render/src/viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export interface IScrollObserverParam {
/**
* scrollX for viewport
*/
actualScrollX?: number;
actualScrollY?: number;
viewportScrollX?: number;
viewportScrollY?: number;
limitX?: number;
limitY?: number;
isTrigger?: boolean;
Expand Down Expand Up @@ -252,9 +252,6 @@ export class Viewport {
this._mainCanvasResizeHandler();
});
this._mainCanvasResizeHandler();
if (this.viewportKey === 'viewMain') {
console.log('viewMain init');
}
}

initCacheCanvas(props?: IViewProps) {
Expand Down Expand Up @@ -532,8 +529,8 @@ export class Viewport {
scrollY: this.scrollY,
x,
y,
actualScrollX: this.viewportScrollX,
actualScrollY: this.viewportScrollY,
viewportScrollX: this.viewportScrollX,
viewportScrollY: this.viewportScrollY,
limitX: this._scrollBar?.limitX,
limitY: this._scrollBar?.limitY,
isTrigger,
Expand Down Expand Up @@ -655,7 +652,7 @@ export class Viewport {
// this._deltaScrollY = this.scrollY - this._preScrollY;
this._preScrollX = this.scrollX;
this._preScrollY = this.scrollY;
const { scrollX, scrollY, actualScrollX, actualScrollY } = current;
const { scrollX, scrollY, viewportScrollX, viewportScrollY } = current;
if (scrollX !== undefined) {
this.scrollX = scrollX;
}
Expand All @@ -664,16 +661,16 @@ export class Viewport {
this.scrollY = scrollY;
}

if (actualScrollX !== undefined) {
if (viewportScrollX !== undefined) {
this.preViewportScrollX = this.viewportScrollX;
this.viewportScrollX = actualScrollX;
this._deltaViewportScrollX = actualScrollX - this.preViewportScrollX;
this.viewportScrollX = viewportScrollX;
this._deltaViewportScrollX = viewportScrollX - this.preViewportScrollX;
}

if (actualScrollY !== undefined) {
if (viewportScrollY !== undefined) {
this.preViewportScrollY = this.viewportScrollY;
this.viewportScrollY = actualScrollY;
this._deltaViewportScrollY = actualScrollY - this.preViewportScrollY;
this.viewportScrollY = viewportScrollY;
this._deltaViewportScrollY = viewportScrollY - this.preViewportScrollY;
}
return this;
}
Expand Down Expand Up @@ -1145,21 +1142,6 @@ export class Viewport {
this.cacheBound = this._viewBound;
this.preCacheBound = null;

// const contentWidth = (this._scene.width - this._paddingEndX) * this._scene.scaleX;
// const contentHeight = (this._scene.height - this._paddingEndY) * this._scene.scaleY;
// // @ts-expect-error
// if (this.viewportKey === 'sheetViewMain') {
// console.log('cotnentHeight', contentHeight, window.sms?._searchParamForScroll);
// }

// if (this._scrollBar) {
// this._scrollBar.resize(width, height, contentWidth, contentHeight);
// const { x, y } = this.transViewportScroll2ScrollValue(viewportScrollX, viewportScrollY);
// this.scrollTo({
// x,
// y,
// });
// }
this.markForceDirty(true);
}

Expand All @@ -1169,10 +1151,6 @@ export class Viewport {
const { width, height } = this._getViewPortSize();
const contentWidth = (this._scene.width - this._paddingEndX) * this._scene.scaleX;
const contentHeight = (this._scene.height - this._paddingEndY) * this._scene.scaleY;
// @ts-expect-error
if (this.viewportKey === 'sheetViewMain') {
console.log('cotnentHeight', contentHeight, window.sms?._searchParamForScroll);
}

if (this._scrollBar) {
this._scrollBar.resize(width, height, contentWidth, contentHeight);
Expand Down Expand Up @@ -1256,8 +1234,7 @@ export class Viewport {
y: number;
},
x?: number,
y?: number,
isTrigger = true
y?: number
) {
clearTimeout(this._scrollStopNum);
this._scrollStopNum = setTimeout(() => {
Expand All @@ -1267,11 +1244,10 @@ export class Viewport {
scrollY: this.scrollY,
x,
y,
actualScrollX: scroll.x,
actualScrollY: scroll.y,
viewportScrollX: scroll.x,
viewportScrollY: scroll.y,
limitX: this._scrollBar?.limitX,
limitY: this._scrollBar?.limitY,
isTrigger,
});
}, 2);
}
Expand All @@ -1286,7 +1262,7 @@ export class Viewport {
* @param scrollBarPos viewMain 滚动条的位置
* @param isTrigger
*/
private _scrollToScrollbarPos(scrollType: SCROLL_TYPE, scrollBarPos: IScrollBarPosition, isTrigger = true) {
private _scrollToScrollbarPos(scrollType: SCROLL_TYPE, scrollBarPos: IScrollBarPosition, isTrigger?: boolean) {
const { x, y } = scrollBarPos;
if (this._scrollBar == null) {
return;
Expand Down Expand Up @@ -1317,7 +1293,7 @@ export class Viewport {
}

const limited = this.limitedScroll(); // 限制滚动范围
isTrigger && this.onScrollBeforeObserver.notifyObservers({
this.onScrollBeforeObserver.notifyObservers({
viewport: this,
scrollX: this.scrollX,
scrollY: this.scrollY,
Expand All @@ -1337,19 +1313,22 @@ export class Viewport {
this.viewportScrollY = vpScroll.y;

// scroll.render-controller@onScrollAfterObserver ---> setScrollInfo but no notify
isTrigger && this.onScrollAfterObserver.notifyObservers({
// calc startRow & offset by viewportScrollXY, then update scrollInfo
// other viewports, rowHeader & colHeader depend on this notify
this.onScrollAfterObserver.notifyObservers({
viewport: this,
scrollX: this.scrollX,
scrollY: this.scrollY,
x,
y,
actualScrollX: vpScroll.x,
actualScrollY: vpScroll.y,
viewportScrollX: vpScroll.x,
viewportScrollY: vpScroll.y,
limitX: this._scrollBar?.limitX,
limitY: this._scrollBar?.limitY,
isTrigger,
});

this._triggerScrollStop(vpScroll, x, y, isTrigger);
this._triggerScrollStop(vpScroll, x, y);

return limited;
}
Expand Down Expand Up @@ -1395,7 +1374,6 @@ export class Viewport {
: 0b00;

const shouldCacheUpdate = nearEdge | viewBoundOutCacheArea;
// console.log(`shouldCacheUpdate${shouldCacheUpdate}`, `${this.viewportKey}:`, this.preCacheBound, this.cacheBound, this.viewBound, this._preCacheVisibleBound);
return shouldCacheUpdate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const SetSelectionFrozenCommand: ICommand<ISetSelectionFrozenCommandParam
const currentSelection = selections[selections?.length - 1];
const { range } = currentSelection;
const scrollManagerService = accessor.get(ScrollManagerService);
const { sheetViewStartRow = 0, sheetViewStartColumn = 0 } = scrollManagerService.getCurrentScroll() || {};
const { sheetViewStartRow = 0, sheetViewStartColumn = 0 } = scrollManagerService.getCurrentScrollInfo() || {};
let startRow;
let startColumn;
let ySplit;
Expand Down
11 changes: 4 additions & 7 deletions packages/sheets-ui/src/commands/commands/set-scroll.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface ISetScrollRelativeCommandParams {
export const SetScrollRelativeCommand: ICommand<ISetScrollRelativeCommandParams> = {
id: 'sheet.command.set-scroll-relative',
type: CommandType.COMMAND,
// offsetXY derived from mouse wheel event
handler: async (accessor, params = { offsetX: 0, offsetY: 0 }) => {
const commandService = accessor.get(ICommandService);
const scrollManagerService = accessor.get(ScrollManagerService);
Expand All @@ -45,26 +46,22 @@ export const SetScrollRelativeCommand: ICommand<ISetScrollRelativeCommandParams>

const { unitId, subUnitId, worksheet } = target;
const { xSplit, ySplit } = worksheet.getConfig().freeze;
const currentScroll = scrollManagerService.getCurrentScroll();
const currentScroll = scrollManagerService.getCurrentScrollInfo();
const { offsetX = 0, offsetY = 0 } = params || {};
const {
sheetViewStartRow = 0,
sheetViewStartColumn = 0,
offsetX: currentOffsetX = 0,
offsetY: currentOffsetY = 0,
scrollLeft,
scrollTop,
} = currentScroll || {};

return commandService.executeCommand(SetScrollOperation.id, {
unitId,
sheetId: subUnitId,
sheetViewStartRow: sheetViewStartRow + ySplit,
sheetViewStartColumn: sheetViewStartColumn + xSplit,
offsetX: currentOffsetX + offsetX,
offsetX: currentOffsetX + offsetX, // currentOffsetX, offsetX 0, -179, offsetX may be negative or over max
offsetY: currentOffsetY + offsetY,
scrollLeft,
scrollTop,
});
},
};
Expand Down Expand Up @@ -95,7 +92,7 @@ export const ScrollCommand: ICommand<IScrollCommandParams> = {
if (!target) return false;

const { workbook, worksheet } = target;
const currentScroll = scrollManagerService.getCurrentScroll();
const currentScroll = scrollManagerService.getCurrentScrollInfo();

if (!worksheet) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ export const SetScrollOperation: IOperation<IScrollManagerInsertParam> = {
const worksheet = workbook!.getSheetBySheetId(params!.sheetId);
const { xSplit, ySplit } = worksheet!.getConfig().freeze;

if (!worksheet) return false;
const config = worksheet.getConfig();
config.scrollLeft = params.scrollLeft || 0;
config.scrollTop = params.scrollTop || 0;

scrollManagerService.setScrollInfo({
...params,
sheetViewStartRow: params.sheetViewStartRow - ySplit,
Expand Down
6 changes: 3 additions & 3 deletions packages/sheets-ui/src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,18 @@ export function transformPosition2Offset(x: number, y: number, scene: Scene, ske
const freezeWidth = endSheetView.startX - startSheetView.startX;
const freezeHeight = endSheetView.startY - startSheetView.startY;

const { top, left, viewportScrollX: actualScrollX, viewportScrollY: actualScrollY } = viewMain;
const { top, left, viewportScrollX, viewportScrollY } = viewMain;
let offsetX: number;
// viewMain or viewTop
if (x > left) {
offsetX = (x - actualScrollX) * scaleX;
offsetX = (x - viewportScrollX) * scaleX;
} else {
offsetX = ((freezeWidth + rowHeaderWidth) - (left - x)) * scaleX;
}

let offsetY: number;
if (y > top) {
offsetY = (y - actualScrollY) * scaleY;
offsetY = (y - viewportScrollY) * scaleY;
} else {
offsetY = ((freezeHeight + columnHeaderHeight) - (top - y)) * scaleX;
}
Expand Down
Loading

0 comments on commit b17b616

Please sign in to comment.