Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix: fixed the issue where scrolling was reset when the auto fill passed through the freeze line (#5437)

wpxp1234566494b004314b
diff --git a/packages/sheets-ui/src/services/selection/selection-shape-extension.ts b/packages/sheets-ui/src/services/selection/selection-shape-extension.ts
index fa601f3383..72db0965a0 100644
--- a/packages/sheets-ui/src/services/selection/selection-shape-extension.ts
+++ b/packages/sheets-ui/src/services/selection/selection-shape-extension.ts
@@ -779,6 +779,7 @@ export class SelectionShapeExtension {
this._control.selectionFilling$.next(this._targetSelection);
}
+ // eslint-disable-next-line max-lines-per-function
private _autoFillForPointerdown(evt: IMouseEvent | IPointerEvent) {
const { offsetX: evtOffsetX, offsetY: evtOffsetY } = evt;
@@ -906,10 +907,13 @@ export class SelectionShapeExtension {
}
if (this._isSelectionInViewport(movingRange, currentViewport)) {
- viewportMain.scrollToBarPos({
- x: scrollTimer.scrollTimerType === ScrollTimerType.X ? 0 : undefined,
- y: scrollTimer.scrollTimerType === ScrollTimerType.Y ? 0 : undefined,
- });
+ if (this._viewportMainScrollBarNeedResetPosition(scrollTimer.scrollTimerType, this._activeViewport.viewportKey, currentViewport.viewportKey)) {
+ viewportMain.scrollToBarPos({
+ x: scrollTimer.scrollTimerType === ScrollTimerType.X ? 0 : undefined,
+ y: scrollTimer.scrollTimerType === ScrollTimerType.Y ? 0 : undefined,
+ });
+ }
+
this._activeViewport = currentViewport;
}
}
@@ -937,6 +941,29 @@ export class SelectionShapeExtension {
});
}
+ private _viewportMainScrollBarNeedResetPosition(scrollTimerType: ScrollTimerType, activeViewportKey: string, currentViewportKey: string): boolean {
+ // When the auto fill operation will pass through freeze position, the viewport main scroll bar needs to be reset to the left or top position.
+ // The viewport main scroll bar needs to be reset to the left position only when the auto fill operation direction is from left to right.
+ if (
+ scrollTimerType === ScrollTimerType.X &&
+ (activeViewportKey === SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT || activeViewportKey === SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP) &&
+ (currentViewportKey === SHEET_VIEWPORT_KEY.VIEW_MAIN || currentViewportKey === SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP)
+ ) {
+ return true;
+ }
+
+ // The viewport main scroll bar needs to be reset to the top position only when the auto fill operation direction is from top to bottom.
+ if (
+ scrollTimerType === ScrollTimerType.Y &&
+ (activeViewportKey === SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP || activeViewportKey === SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP) &&
+ (currentViewportKey === SHEET_VIEWPORT_KEY.VIEW_MAIN || currentViewportKey === SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)
+ ) {
+ return true;
+ }
+
+ return false;
+ }
+
private _hasMergeInRange(startRow: number, startColumn: number, endRow: number, endColumn: number) {
return this._skeleton.worksheet.getMergedCellRange(startRow, startColumn, endRow, endColumn).length > 0;
}