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: hyper-link ref-range error on filter (#3135)

zhangw014dd6796bce
diff --git a/packages/design/src/components/popup/index.module.less b/packages/design/src/components/popup/index.module.less
index 14af4e449c..96fdf82479 100644
--- a/packages/design/src/components/popup/index.module.less
+++ b/packages/design/src/components/popup/index.module.less
@@ -1,6 +1,6 @@
.popup-absolute {
position: absolute;
- z-index: 100;
+ z-index: 1000;
top: -9999px;
left: -9999px;
}
diff --git a/packages/sheets-hyper-link/src/controllers/ref-range.controller.ts b/packages/sheets-hyper-link/src/controllers/ref-range.controller.ts
index 94a1976feb..e2a72544b0 100644
--- a/packages/sheets-hyper-link/src/controllers/ref-range.controller.ts
+++ b/packages/sheets-hyper-link/src/controllers/ref-range.controller.ts
@@ -17,7 +17,7 @@
import type { IDisposable, IRange, Nullable } from '@univerjs/core';
import { Disposable, ICommandService, Inject, isValidRange, LifecycleStages, OnLifecycle, sequenceExecuteAsync, toDisposable } from '@univerjs/core';
import type { EffectRefRangeParams } from '@univerjs/sheets';
-import { handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests, RefRangeService, SheetsSelectionsService } from '@univerjs/sheets';
+import { handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests, handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests, RefRangeService, SheetsSelectionsService } from '@univerjs/sheets';
import type { IAddHyperLinkMutationParams, ICellHyperLink, IRemoveHyperLinkMutationParams, IUpdateHyperLinkMutationParams, IUpdateHyperLinkRefMutationParams } from '@univerjs/sheets-hyper-link';
import { AddHyperLinkMutation, HyperLinkModel, RemoveHyperLinkMutation, UpdateHyperLinkMutation, UpdateHyperLinkRefMutation } from '@univerjs/sheets-hyper-link';
import { deserializeRangeWithSheet, serializeRange } from '@univerjs/engine-formula';
@@ -105,7 +105,8 @@ export class SheetsHyperLinkRefRangeController extends Disposable {
};
const handleRefRangeChange = (commandInfo: EffectRefRangeParams) => {
- const resultRange = handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(oldRange, commandInfo, { selectionManagerService: this._selectionManagerService });
+ const resultRanges = handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(oldRange, commandInfo, { selectionManagerService: this._selectionManagerService });
+ const resultRange = Array.isArray(resultRanges) ? resultRanges[0] : resultRanges;
if (resultRange && resultRange.startColumn === oldRange.startColumn && resultRange.startRow === oldRange.startRow) {
return {
undos: [],
diff --git a/packages/sheets-thread-comment-base/src/controllers/sheets-thread-comment-ref-range.controller.ts b/packages/sheets-thread-comment-base/src/controllers/sheets-thread-comment-ref-range.controller.ts
index 434f7dd037..d28e9bd5ab 100644
--- a/packages/sheets-thread-comment-base/src/controllers/sheets-thread-comment-ref-range.controller.ts
+++ b/packages/sheets-thread-comment-base/src/controllers/sheets-thread-comment-ref-range.controller.ts
@@ -17,7 +17,7 @@
import type { IDisposable, IRange, Nullable } from '@univerjs/core';
import { Disposable, ICommandService, Inject, LifecycleStages, OnLifecycle, sequenceExecuteAsync, toDisposable } from '@univerjs/core';
import type { EffectRefRangeParams } from '@univerjs/sheets';
-import { handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests, RefRangeService, SheetsSelectionsService } from '@univerjs/sheets';
+import { handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests, RefRangeService, SheetsSelectionsService } from '@univerjs/sheets';
import type { IAddCommentMutationParams, IUpdateCommentRefMutationParams } from '@univerjs/thread-comment';
import { AddCommentMutation, DeleteCommentMutation, ThreadCommentModel, UpdateCommentRefMutation } from '@univerjs/thread-comment';
import { serializeRange, singleReferenceToGrid } from '@univerjs/engine-formula';
@@ -115,7 +115,8 @@ export class SheetsThreadCommentRefRangeController extends Disposable {
this._disposableMap.set(
this._getIdWithUnitId(unitId, subUnitId, commentId),
this._refRangeService.registerRefRange(oldRange, (commandInfo: EffectRefRangeParams) => {
- const resultRange = handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(oldRange, commandInfo, { selectionManagerService: this._selectionManagerService });
+ const resultRanges = handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(oldRange, commandInfo, { selectionManagerService: this._selectionManagerService });
+ const resultRange = Array.isArray(resultRanges) ? resultRanges[0] : resultRanges;
if (resultRange && resultRange.startColumn === oldRange.startColumn && resultRange.startRow === oldRange.startRow) {
return {
undos: [],
diff --git a/packages/sheets/src/commands/commands/remove-row-col.command.ts b/packages/sheets/src/commands/commands/remove-row-col.command.ts
index ce00bb504e..9b767f56d2 100644
--- a/packages/sheets/src/commands/commands/remove-row-col.command.ts
+++ b/packages/sheets/src/commands/commands/remove-row-col.command.ts
@@ -45,6 +45,11 @@ import { getSheetCommandTarget } from './utils/target-util';
export interface IRemoveRowColCommandParams {
range: IRange;
}
+
+export interface IRemoveRowColCommandInterceptParams extends IRemoveRowColCommandParams {
+ ranges?: IRange[];
+}
+
export const RemoveRowCommandId = 'sheet.command.remove-row';
/**
* This command would remove the selected rows. These selected rows can be non-continuous.
@@ -102,7 +107,7 @@ export const RemoveRowCommand: ICommand<IRemoveRowColCommandParams> = {
const canPerform = await sheetInterceptorService.beforeCommandExecute({
id: RemoveRowCommand.id,
- params: { range: totalRange } as IRemoveRowColCommandParams,
+ params: { range: totalRange, ranges } as IRemoveRowColCommandInterceptParams,
});
if (!canPerform) {
@@ -136,7 +141,7 @@ export const RemoveRowCommand: ICommand<IRemoveRowColCommandParams> = {
const intercepted = sheetInterceptorService.onCommandExecute({
id: RemoveRowCommand.id,
- params: { range: totalRange } as IRemoveRowColCommandParams,
+ params: { range: totalRange, ranges } as IRemoveRowColCommandInterceptParams,
});
const commandService = accessor.get(ICommandService);
diff --git a/packages/sheets/src/index.ts b/packages/sheets/src/index.ts
index 42127d6287..4d09f11ada 100644
--- a/packages/sheets/src/index.ts
+++ b/packages/sheets/src/index.ts
@@ -93,6 +93,7 @@ export {
handleCommonDefaultRangeChangeWithEffectRefCommands,
handleDefaultRangeChangeWithEffectRefCommands,
handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests,
+ handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests,
} from './services/ref-range/util';
export { INTERCEPTOR_POINT, InterceptCellContentPriority } from './services/sheet-interceptor/interceptor-const';
export { SheetInterceptorService } from './services/sheet-interceptor/sheet-interceptor.service';
@@ -206,7 +207,7 @@ export {
type IMoveColsCommandParams,
} from './commands/commands/move-rows-cols.command';
export { RemoveDefinedNameCommand } from './commands/commands/remove-defined-name.command';
-export { RemoveRowCommand, RemoveColCommand, type IRemoveRowColCommandParams } from './commands/commands/remove-row-col.command';
+export { RemoveRowCommand, RemoveColCommand, type IRemoveRowColCommandParams, type IRemoveRowColCommandInterceptParams } from './commands/commands/remove-row-col.command';
export { RemoveSheetCommand, type IRemoveSheetCommandParams } from './commands/commands/remove-sheet.command';
export { RemoveWorksheetMergeCommand } from './commands/commands/remove-worksheet-merge.command';
export { ReorderRangeCommand, type IReorderRangeCommandParams } from './commands/commands/reorder-range.command';
diff --git a/packages/sheets/src/services/ref-range/__tests__/utils.spec.ts b/packages/sheets/src/services/ref-range/__tests__/utils.spec.ts
index b9617bf502..ed7caf6e41 100644
--- a/packages/sheets/src/services/ref-range/__tests__/utils.spec.ts
+++ b/packages/sheets/src/services/ref-range/__tests__/utils.spec.ts
@@ -36,6 +36,7 @@ import {
handleMoveRangeCommon,
handleMoveRows,
handleMoveRowsCommon,
+ handleRemoveRowCommon,
runRefRangeMutations,
} from '../util';
import { RemoveSheetMutation } from '../../../commands/mutations/remove-sheet.mutation';
@@ -1452,5 +1453,20 @@ describe('test different situations of adjustRangeOnMutation', () => {
const result = adjustRangeOnMutation(range, mutation);
expect(result).toEqual({ startRow: 7, endRow: 9, startColumn: 1, endColumn: 1 });
});
+
+ it('should be delete', () => {
+ const targetRange: IRange = { startRow: 5, endRow: 7, startColumn: 1, endColumn: 1 };
+ const resultRange = handleRemoveRowCommon({ range: { ...targetRange } }, targetRange);
+ expect(resultRange.length).toBe(0);
+
+ const resultRange2 = handleRemoveRowCommon({ range: { ...targetRange } }, { ...targetRange, startRow: 4 });
+ expect(resultRange2).toEqual([{ startRow: 4, endRow: 4, startColumn: 1, endColumn: 1 }]);
+ });
+
+ it('should not be delete ', () => {
+ const targetRange: IRange = { startRow: 5, endRow: 7, startColumn: 1, endColumn: 1 };
+ const resultRange = handleRemoveRowCommon({ range: { ...targetRange }, ranges: [{ startRow: 5, endRow: 5, startColumn: 1, endColumn: 1 }, { startRow: 6, endRow: 6, startColumn: 1, endColumn: 1 }] }, targetRange);
+ expect(resultRange).toEqual([{ startRow: 5, endRow: 5, startColumn: 1, endColumn: 1 }]);
+ });
});
});
diff --git a/packages/sheets/src/services/ref-range/util.ts b/packages/sheets/src/services/ref-range/util.ts
index 18d8093b43..5375397103 100644
--- a/packages/sheets/src/services/ref-range/util.ts
+++ b/packages/sheets/src/services/ref-range/util.ts
@@ -27,6 +27,7 @@ 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 { IRemoveRowColCommandInterceptParams } from '../../commands/commands/remove-row-col.command';
import type {
EffectRefRangeParams,
IDeleteRangeMoveLeftCommand,
@@ -872,6 +873,24 @@ export const handleDeleteRangeMoveUpCommon = (param: IDeleteRangeMoveUpCommand,
return queryObjectMatrix(matrix, (v) => v === 1);
};
+export const handleRemoveRowCommon = (param: IRemoveRowColCommandInterceptParams, targetRange: IRange) => {
+ const ranges = param.ranges ?? [param.range];
+ const matrix = new ObjectMatrix();
+
+ Range.foreach(targetRange, (row, col) => {
+ matrix.setValue(row, col, 1);
+ });
+
+ ranges.forEach((range) => {
+ const startRow = range.startRow;
+ const endRow = range.endRow;
+ const count = endRow - startRow + 1;
+ matrix.removeRows(startRow, count);
+ });
+
+ return queryObjectMatrix(matrix, (value) => value === 1);
+};
+
export const runRefRangeMutations = (operators: IOperator[], range: IRange) => {
let result: Nullable<IRange> = { ...range };
operators.forEach((operator) => {
@@ -1032,14 +1051,27 @@ export const handleCommonDefaultRangeChangeWithEffectRefCommands = (range: IRang
break;
}
case EffectRefRangId.RemoveRowCommandId: {
- operator = handleIRemoveRow(commandInfo as IRemoveRowColCommand, range);
- break;
+ return handleRemoveRowCommon(commandInfo.params as IRemoveRowColCommandInterceptParams, range);
}
}
const resultRange = runRefRangeMutations(operator, range);
return resultRange;
};
+export const handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests = (range: IRange, commandInfo: ICommandInfo, deps: { selectionManagerService: SheetsSelectionsService }) => {
+ const skipCommands = [DeleteRangeMoveLeftCommand.id, DeleteRangeMoveUpCommand.id];
+ if (skipCommands.includes(commandInfo.id)) {
+ return handleCommonDefaultRangeChangeWithEffectRefCommands(range, commandInfo);
+ }
+
+ const effectRanges = getEffectedRangesOnCommand(commandInfo as EffectRefRangeParams, deps);
+ if (effectRanges.some((effectRange) => Rectangle.intersects(effectRange, range))) {
+ return handleCommonDefaultRangeChangeWithEffectRefCommands(range, commandInfo);
+ }
+
+ return range;
+};
+
/**
* This function should work as a pure function.
*