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: move range selection not showing when dragging a selection (#4082)

lumix9310099cc4c8
diff --git a/packages/sheets-ui/src/services/selection/selection-render.service.ts b/packages/sheets-ui/src/services/selection/selection-render.service.ts
index 7299aa9711..10e2443b68 100644
--- a/packages/sheets-ui/src/services/selection/selection-render.service.ts
+++ b/packages/sheets-ui/src/services/selection/selection-render.service.ts
@@ -145,13 +145,10 @@ export class SheetSelectionRenderService extends BaseSelectionRenderService impl
}
private _initSelectionChangeListener(): void {
- // only ref selection need this,
- // this.disposeWithMe(merge(this._workbookSelections.selectionMoveEnd$, this._workbookSelections.selectionSet$).subscribe((selectionWithStyleList) => {
- // // this._reset();
- // // for (const selectionWithStyle of selectionWithStyleList) {
- // // this._addSelectionControlByModelData(selectionWithStyle);
- // // }
- // }));
+ // normal selection: after dragging selection(move end)
+ this.disposeWithMe(this._workbookSelections.selectionMoveEnd$.subscribe((selectionWithStyleList) => {
+ this.resetSelectionsByModelData(selectionWithStyleList);
+ }));
}
private _initUserActionSyncListener(): void {
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 8e37233eb1..b4d7512c45 100644
--- a/packages/sheets-ui/src/services/selection/selection-shape-extension.ts
+++ b/packages/sheets-ui/src/services/selection/selection-shape-extension.ts
@@ -27,7 +27,7 @@ import type { SelectionControl } from './selection-control';
import { SheetSkeletonManagerService } from '../sheet-skeleton-manager.service';
import { ISheetSelectionRenderService } from './base-selection-render.service';
import { genNormalSelectionStyle, RANGE_FILL_PERMISSION_CHECK, RANGE_MOVE_PERMISSION_CHECK } from './const';
-import { attachSelectionWithCoord } from './util';
+import { attachPrimaryWithCoord, attachSelectionWithCoord } from './util';
const HELPER_SELECTION_TEMP_NAME = '__SpreadsheetHelperSelectionTempRect';
@@ -67,6 +67,9 @@ export class SelectionShapeExtension {
private _scenePointerUpSub: Nullable<Subscription>;
+ /**
+ * The shadow selection under cursor when move whole selection control(for moving normal selection)
+ */
private _helperSelection: Nullable<Rect>;
private _scrollTimer!: ScrollTimer;
@@ -240,33 +243,23 @@ export class SelectionShapeExtension {
style: null,
};
const selectionWithCoord = attachSelectionWithCoord(selection, this._skeleton);
- // const startCell = this._skeleton.getNoMergeCellPositionByIndex(startRow, startColumn);
- // const endCell = this._skeleton.getNoMergeCellPositionByIndex(endRow, endColumn);
- // const startY = startCell?.startY || 0;
- // const endY = endCell?.endY || 0;
- // const startX = startCell?.startX || 0;
- // const endX = endCell?.endX || 0;
+ const startCell = this._skeleton.getNoMergeCellPositionByIndex(startRow, startColumn);
+ const endCell = this._skeleton.getNoMergeCellPositionByIndex(endRow, endColumn);
+ const startY = startCell?.startY || 0;
+ const endY = endCell?.endY || 0;
+ const startX = startCell?.startX || 0;
+ const endX = endCell?.endX || 0;
- // this._helperSelection?.transformByState({
- // left: startX,
- // top: startY,
- // width: endX - startX,
- // height: endY - startY,
- // });
+ this._helperSelection?.transformByState({
+ left: startX,
+ top: startY,
+ width: endX - startX,
+ height: endY - startY,
+ });
- // this._targetSelection = {
- // startY,
- // endY,
- // startX,
- // endX,
- // startRow,
- // endRow,
- // startColumn,
- // endColumn,
- // };
- // const primaryWithCoordAndMergeInfo = attachPrimaryWithCoord(this._skeleton, primaryCell);
- // this._control.updateRange(this._targetSelection, primaryWithCoordAndMergeInfo);
- this._control.updateRangeBySelectionWithCoord(selectionWithCoord);
+ this._targetSelection = { ...selectionWithCoord.rangeWithCoord };
+ const primaryWithCoordAndMergeInfo = attachPrimaryWithCoord(this._skeleton, primaryCell);
+ this._control.updateCurrCell(primaryWithCoordAndMergeInfo);
this._control.selectionMoving$.next(selectionWithCoord.rangeWithCoord);
}
@@ -583,7 +576,7 @@ export class SelectionShapeExtension {
const primaryCell = this._skeleton.getCellWithMergeInfoByIndex(startRow, startColumn);
const selectionWithStyle: ISelectionWithStyle = { range, primary: primaryCell, style: null };
const selectionRangeWithCoord = attachSelectionWithCoord(selectionWithStyle, this._skeleton);
- this._targetSelection = selectionRangeWithCoord.rangeWithCoord;
+ this._targetSelection = { ...selectionRangeWithCoord.rangeWithCoord };
// const startCell = this._skeleton.getNoMergeCellPositionByIndex(finalStartRow, finalStartColumn);
// const endCell = this._skeleton.getNoMergeCellPositionByIndex(finalEndRow, finalEndColumn);