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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(sheet): selection shift bug (#626)
Univer1ea59210953d
diff --git a/packages/sheets-ui/src/services/selection/selection-render.service.ts b/packages/sheets-ui/src/services/selection/selection-render.service.tsindex 34c7bc4c1e..fc8e5efe5f 100644--- a/packages/sheets-ui/src/services/selection/selection-render.service.ts+++ b/packages/sheets-ui/src/services/selection/selection-render.service.ts@@ -493,21 +493,64 @@ export class SelectionRenderService implements ISelectionRenderService {const currentCell = selectionControl && selectionControl.model.currentCell;if (selectionControl && evt.shiftKey && currentCell) {- const { actualRow, actualColumn } = currentCell;+ const { actualRow, actualColumn, mergeInfo: actualMergeInfo } = currentCell;- // TODO startCell position calculate error- const startCell = skeleton.getNoMergeCellPositionByIndex(actualRow, actualColumn, scaleX, scaleY);- const endCell = skeleton.getNoMergeCellPositionByIndex(endRow, endColumn, scaleX, scaleY);+ /**+ * Get the maximum range selected based on the two cells selected with Shift.+ */++ const newStartRow = Math.min(actualRow, startSelectionRange.startRow, actualMergeInfo.startRow);++ const newEndRow = Math.max(actualRow, startSelectionRange.endRow, actualMergeInfo.endRow);++ const newStartColumn = Math.min(actualColumn, startSelectionRange.startColumn, actualMergeInfo.startColumn);++ const newEndColumn = Math.max(actualColumn, startSelectionRange.endColumn, actualMergeInfo.endColumn);++ /**+ * Calculate whether there are merged cells within the range. If there are, recursively expand the selection again.+ */+ const bounding = skeleton.getMergeBounding(newStartRow, newStartColumn, newEndRow, newEndColumn);++ const startCell = skeleton.getNoMergeCellPositionByIndex(+ bounding.startRow,+ bounding.startColumn,+ scaleX,+ scaleY+ );++ const endCell = skeleton.getNoMergeCellPositionByIndex(bounding.endRow, bounding.endColumn, scaleX, scaleY);const newSelectionRange = {- startColumn: actualColumn,- startRow: actualRow,- endColumn: startSelectionRange.startColumn,- endRow: startSelectionRange.startRow,- startY: startCell?.startY || 0,- endY: endCell?.endY || 0,- startX: startCell?.startX || 0,- endX: endCell?.endX || 0,+ startColumn: bounding.startColumn,+ startRow: bounding.startRow,+ endColumn: bounding.endColumn,+ endRow: bounding.endRow,++ startY: startCell.startY,+ endY: endCell.endY,+ startX: startCell.startX,+ endX: endCell.endX,++ rangeType,+ };++ /**+ * When expanding the selection with the Shift key,+ * the original highlighted cell should remain unchanged.+ * If the highlighted cell is a merged cell, the selection needs to be expanded.+ */+ const activeCell = skeleton.getCellByIndex(actualRow, actualColumn, scaleX, scaleY);++ this._startSelectionRange = {+ startColumn: activeCell.mergeInfo.startColumn,+ startRow: activeCell.mergeInfo.startRow,+ endColumn: activeCell.mergeInfo.endColumn,+ endRow: activeCell.mergeInfo.endRow,+ startY: activeCell.mergeInfo.startY || 0,+ endY: activeCell.mergeInfo.endY || 0,+ startX: activeCell.mergeInfo.startX || 0,+ endX: activeCell.mergeInfo.endX || 0,rangeType,};diff --git a/packages/sheets/src/basics/selection.ts b/packages/sheets/src/basics/selection.tsindex 975bfd57d3..2552d39979 100644--- a/packages/sheets/src/basics/selection.ts+++ b/packages/sheets/src/basics/selection.ts@@ -10,7 +10,7 @@ import type {import { makeCellRangeToRangeData } from '@univerjs/core';import { getCellInfoInMergeData } from '@univerjs/engine-render';-export const SELECTION_CONTROL_BORDER_BUFFER_WIDTH = 2; // The draggable range of the selection is too thin, making it easy for users to miss. Therefore, a buffer gap is provided to make it easier for users to select.+export const SELECTION_CONTROL_BORDER_BUFFER_WIDTH = 1; // The draggable range of the selection is too thin, making it easy for users to miss. Therefore, a buffer gap is provided to make it easier for users to select.export const SELECTION_CONTROL_BORDER_BUFFER_COLOR = 'rgba(255,255,255, 0.01)';