Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unexpected cross viewport selection because it counts rowheader #3296

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions packages/engine-render/src/scroll-timer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,16 @@ export enum ScrollTimerType {

export class ScrollTimer {
private _requestNewFrameNumber: number = -1;

private _viewport: Nullable<any>;

private _offsetX: number = 0;

private _offsetY: number = 0;

private _moveX: number = 0;

private _moveY: number = 0;

private _scrollX: number = 0;

private _scrollY: number = 0;

/**
* Custmize scroll function.
*/
private _scrollFunction: Nullable<(x?: number, y?: number) => void>;

constructor(
Expand Down Expand Up @@ -97,7 +92,8 @@ export class ScrollTimer {
this._runRenderLoop();
}

private _scroll(viewport: Nullable<Viewport>) {
//eslint-disable-next-line complexity
private _autoScroll(viewport: Nullable<Viewport>) {
const topBounding = viewport?.top || 0;
const bottomBounding = topBounding + (viewport?.height || 0);
const leftBounding = viewport?.left || 0;
Expand Down Expand Up @@ -156,7 +152,7 @@ export class ScrollTimer {
const ancestorScene = this._findAncestorScene(viewport?.scene);
const newViewport = this.getViewportByCoord(ancestorScene);
if (newViewport) {
this._scroll(newViewport);
this._autoScroll(newViewport);
}
}
}
Expand Down Expand Up @@ -185,8 +181,10 @@ export class ScrollTimer {
}

private _runRenderLoop() {
this._scroll(this._viewport);
this._scrollFunction && this._scrollFunction(this._scrollX, this._scrollY);
this._autoScroll(this._viewport);
if (this._scrollFunction) {
this._scrollFunction(this._scrollX, this._scrollY);
}
this._requestNewFrameNumber = requestNewFrame(this._runRenderLoop.bind(this));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,8 @@ export class BaseSelectionRenderService extends Disposable implements ISheetSele
}

/**
* Init pointer move listener, bind in each pointer down, unbind in each pointer up
* Init pointer move listener in each pointer down, unbind in each pointer up.
* Both cell selections and row-column selections are supported by this method.
* @param viewportMain
* @param activeSelectionControl
* @param rangeType
Expand Down Expand Up @@ -582,6 +583,7 @@ export class BaseSelectionRenderService extends Disposable implements ISheetSele
let scrollOffsetX = newMoveOffsetX;
let scrollOffsetY = newMoveOffsetY;

//#region selection cross freezing line
const currentSelection = this.getActiveSelectionControl();
const freeze = this._getFreeze();

Expand All @@ -590,14 +592,27 @@ export class BaseSelectionRenderService extends Disposable implements ISheetSele
scene.getActiveViewportByCoord(Vector2.FromArray([moveOffsetX, moveOffsetY])) ??
this._getViewportByCell(selection?.endRow, selection?.endColumn);

if (startViewport && endViewport && viewportMain) {
const isCrossableViewports = () => {
if (!startViewport || !endViewport || !viewportMain) {
return false;
}
const crossableViewports = [SHEET_VIEWPORT_KEY.VIEW_MAIN,
SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,
SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,
SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT] as string[];
return crossableViewports.includes(startViewport.viewportKey) && crossableViewports.includes(endViewport.viewportKey);
};
if (isCrossableViewports()) {
if (!startViewport || !endViewport || !viewportMain) {
return false;
}

const isCrossingX =
(lastX < viewportMain.left && newMoveOffsetX > viewportMain.left) ||
(lastX > viewportMain.left && newMoveOffsetX < viewportMain.left);
const isCrossingY =
(lastY < viewportMain.top && newMoveOffsetY > viewportMain.top) ||
(lastY > viewportMain.top && newMoveOffsetY < viewportMain.top);

if (isCrossingX) {
xCrossTime += 1;
}
Expand Down Expand Up @@ -696,10 +711,13 @@ export class BaseSelectionRenderService extends Disposable implements ISheetSele
lastX = newMoveOffsetX;
lastY = newMoveOffsetY;
}
//#endregion

//#region auto scrolling
this._scrollTimer.scrolling(scrollOffsetX, scrollOffsetY, () => {
this._movingHandler(newMoveOffsetX, newMoveOffsetY, activeSelectionControl, rangeType);
});
//#endregion
});
// #endregion
}
Expand Down
Loading