Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hyper-link ref-range error on filter #3135

Merged
merged 5 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,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';
Expand Down
22 changes: 20 additions & 2 deletions packages/sheets/src/services/ref-range/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -872,6 +873,24 @@ export const handleDeleteRangeMoveUpCommon = (param: IDeleteRangeMoveUpCommand,
return queryObjectMatrix(matrix, (v) => v === 1);
};

export const handleRemoveRowCommon = (param: IRemoveRowColCommandInterceptParams, targetRange: IRange) => {
weird94 marked this conversation as resolved.
Show resolved Hide resolved
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) => {
Expand Down Expand Up @@ -1032,8 +1051,7 @@ 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);
Expand Down
Loading