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(sheets-ui): watch-range error on move-range (#3060)

zhangw7430e849742c
diff --git a/packages/sheets/src/services/ref-range/ref-range.service.ts b/packages/sheets/src/services/ref-range/ref-range.service.ts
index 93f286045f..126fb1c905 100644
--- a/packages/sheets/src/services/ref-range/ref-range.service.ts
+++ b/packages/sheets/src/services/ref-range/ref-range.service.ts
@@ -34,6 +34,8 @@ import {
import { SheetsSelectionsService } from '../selections/selection-manager.service';
import { SheetInterceptorService } from '../sheet-interceptor/sheet-interceptor.service';
import type { ISheetCommandSharedParams } from '../../commands/utils/interface';
+import type { IMoveRangeMutationParams } from '../../commands/mutations/move-range.mutation';
+import { MoveRangeMutation } from '../../commands/mutations/move-range.mutation';
import type { EffectRefRangeParams } from './type';
import { EffectRefRangId } from './type';
import { adjustRangeOnMutation, getEffectedRangesOnMutation } from './util';
@@ -64,12 +66,23 @@ class WatchRange extends Disposable {
}
onMutation(mutation: IMutationInfo<ISheetCommandSharedParams>) {
- if (mutation.params?.unitId !== this._unitId || mutation.params?.subUnitId !== this._subUnitId) {
+ if (mutation.params?.unitId !== this._unitId) {
return;
}
+ // move range don't have subUnitId on params
+ if (mutation.id === MoveRangeMutation.id) {
+ const params = mutation.params as unknown as IMoveRangeMutationParams;
+ if (params.from.subUnitId !== this._subUnitId || params.to.subUnitId !== this._subUnitId) {
+ return;
+ }
+ } else if (mutation.params?.subUnitId !== this._subUnitId) {
+ return;
+ }
+
if (!this._range) {
return;
}
+
if (this._skipIntersects) {
const effectRanges = getEffectedRangesOnMutation(mutation);
if (effectRanges?.some((effectRange) => Rectangle.intersects(effectRange, this._range!))) {
diff --git a/packages/sheets/src/services/ref-range/util.ts b/packages/sheets/src/services/ref-range/util.ts
index 5d4b0555b1..18d8093b43 100644
--- a/packages/sheets/src/services/ref-range/util.ts
+++ b/packages/sheets/src/services/ref-range/util.ts
@@ -25,6 +25,8 @@ import { RemoveColMutation, RemoveRowMutation } from '../../commands/mutations/r
import { InsertColMutation, InsertRowMutation } from '../../commands/mutations/insert-row-col.mutation';
import type { ISheetCommandSharedParams } from '../../commands/utils/interface';
import type { SheetsSelectionsService } from '../selections/selection-manager.service';
+import { DeleteRangeMoveLeftCommand } from '../../commands/commands/delete-range-move-left.command';
+import { DeleteRangeMoveUpCommand } from '../../commands/commands/delete-range-move-up.command';
import type {
EffectRefRangeParams,
IDeleteRangeMoveLeftCommand,
@@ -966,6 +968,11 @@ export const handleDefaultRangeChangeWithEffectRefCommands = (range: IRange, com
};
export const handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests = (range: IRange, commandInfo: ICommandInfo, deps: { selectionManagerService: SheetsSelectionsService }) => {
+ const skipCommands = [DeleteRangeMoveLeftCommand.id, DeleteRangeMoveUpCommand.id];
+ if (skipCommands.includes(commandInfo.id)) {
+ return handleDefaultRangeChangeWithEffectRefCommands(range, commandInfo);
+ }
+
const effectRanges = getEffectedRangesOnCommand(commandInfo as EffectRefRangeParams, deps);
if (effectRanges.some((effectRange) => Rectangle.intersects(effectRange, range))) {
return handleDefaultRangeChangeWithEffectRefCommands(range, commandInfo);
@@ -1124,7 +1131,7 @@ export function adjustRangeOnMutation(range: Readonly<IRange>, mutation: IMutati
}
}
-// eslint-disable-next-line max-lines-per-function
+// eslint-disable-next-line max-lines-per-function, complexity
export function getEffectedRangesOnCommand(command: EffectRefRangeParams, deps: { selectionManagerService: SheetsSelectionsService }) {
const { selectionManagerService } = deps;
switch (command.id) {
@@ -1250,7 +1257,7 @@ export function getEffectedRangesOnMutation(mutation: IMutationInfo<MutationsAff
case MoveRangeMutation.id: {
const params = mutation.params as IMoveRangeMutationParams;
- return [new ObjectMatrix(params.from).getRange(), new ObjectMatrix(params.to).getRange()];
+ return [new ObjectMatrix(params.from.value).getRange(), new ObjectMatrix(params.to.value).getRange()];
}
case InsertColMutation.id: {
const params = mutation.params as IInsertColMutationParams;