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: scroll bugs when selection moves (#266)

YuHong853f97671fa2
diff --git a/packages/base-sheets/src/Controller/Selection.controller.ts b/packages/base-sheets/src/Controller/Selection.controller.ts
index 1246adb62d..80260db663 100644
--- a/packages/base-sheets/src/Controller/Selection.controller.ts
+++ b/packages/base-sheets/src/Controller/Selection.controller.ts
@@ -181,16 +181,20 @@ export class SelectionController extends Disposable {
endRow: viewportEndRow,
endColumn: viewportEndColumn,
} = skeleton.getRowColumnSegment(bounds);
+ let isOverflow = false;
// top overflow
if (selectionStartRow <= viewportStartRow) {
+ isOverflow = true;
startSheetViewRow = selectionStartRow;
}
// left overflow
if (selectionStartColumn <= viewportStartColumn) {
+ isOverflow = true;
startSheetViewColumn = selectionStartColumn;
}
// bottom overflow
if (selectionEndRow >= viewportEndRow) {
+ isOverflow = true;
const minRowAccumulation = rowHeightAccumulation[selectionEndRow] - viewport.height!;
for (let r = viewportStartRow; r <= selectionEndRow; r++) {
if (rowHeightAccumulation[r] >= minRowAccumulation) {
@@ -201,6 +205,7 @@ export class SelectionController extends Disposable {
}
// right overflow
if (selectionEndColumn >= viewportEndColumn) {
+ isOverflow = true;
const minColumnAccumulation = columnWidthAccumulation[selectionEndColumn] - viewport.width!;
for (let c = viewportStartColumn; c <= selectionEndColumn; c++) {
if (columnWidthAccumulation[c] >= minColumnAccumulation) {
@@ -209,6 +214,9 @@ export class SelectionController extends Disposable {
}
}
}
+ if (!isOverflow) {
+ return;
+ }
// sheetViewStartRow and sheetViewStartColumn maybe undefined
const workbook = this._currentUniverService.getCurrentUniverSheetInstance();
this._commandService.executeCommand(ScrollCommand.id, {
diff --git a/packages/base-sheets/src/Controller/scroll.controller.ts b/packages/base-sheets/src/Controller/scroll.controller.ts
index 8598931721..3fcf5a0578 100644
--- a/packages/base-sheets/src/Controller/scroll.controller.ts
+++ b/packages/base-sheets/src/Controller/scroll.controller.ts
@@ -110,31 +110,40 @@ export class ScrollController extends Disposable {
}
const { sheetViewStartRow, sheetViewStartColumn } = param;
- const { startX, startY } = skeleton.getCellByIndex(
- sheetViewStartRow || 0,
- sheetViewStartColumn || 0,
- scaleX,
- scaleY
- );
+
const { tl } = viewportMain.getBounding();
// if both row and column are defined, we should scroll this cell to the top left corner
// the scroll position is absolute position
if (sheetViewStartRow !== undefined && sheetViewStartColumn !== undefined) {
+ const { startX, startY } = skeleton.getCellByIndexWithNoHeader(
+ sheetViewStartRow,
+ sheetViewStartColumn,
+ scaleX,
+ scaleY
+ );
const config = viewportMain.getBarScroll(startX, startY);
viewportMain.scrollTo(config);
+ } else {
+ const { startX, startY } = skeleton.getCellByIndex(
+ sheetViewStartRow || 0,
+ sheetViewStartColumn || 0,
+ scaleX,
+ scaleY
+ );
// if only column is undefined, we should scroll vertically to the cell
// the scroll position is relative position
- } else if (sheetViewStartRow !== undefined) {
- const offsetY = startY - tl.y;
- const config = viewportMain.getBarScroll(0, offsetY);
- viewportMain.scrollBy(config);
- // if only row is undefined, we should scroll horizontally to the cell
- // the scroll position is relative position
- } else if (sheetViewStartColumn !== undefined) {
- const offsetX = startX - tl.x;
- const config = viewportMain.getBarScroll(offsetX, 0);
- viewportMain.scrollBy(config);
+ if (sheetViewStartRow !== undefined) {
+ const offsetY = startY - tl.y;
+ const config = viewportMain.getBarScroll(0, offsetY);
+ viewportMain.scrollBy(config);
+ // if only row is undefined, we should scroll horizontally to the cell
+ // the scroll position is relative position
+ } else if (sheetViewStartColumn !== undefined) {
+ const offsetX = startX - tl.x;
+ const config = viewportMain.getBarScroll(offsetX, 0);
+ viewportMain.scrollBy(config);
+ }
}
});
}