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): fix some APIs, such as setGridLinesColor, were ineffective when setting for inactive worksheets (#6348)

wpxp123456a6cc5b5a910c
diff --git a/packages/sheets-filter/src/controllers/sheets-filter.controller.ts b/packages/sheets-filter/src/controllers/sheets-filter.controller.ts
index 87c45fce67..97e22f7575 100644
--- a/packages/sheets-filter/src/controllers/sheets-filter.controller.ts
+++ b/packages/sheets-filter/src/controllers/sheets-filter.controller.ts
@@ -890,7 +890,7 @@ export class SheetsFilterController extends Disposable {
private _initErrorHandling() {
this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
const params = command.params as IMoveRowsCommandParams;
- const target = getSheetCommandTarget(this._univerInstanceService);
+ const target = getSheetCommandTarget(this._univerInstanceService, params);
if (!target) return;
const { subUnitId, unitId } = target;
diff --git a/packages/sheets-hyper-link/src/controllers/set-range.controller.ts b/packages/sheets-hyper-link/src/controllers/set-range.controller.ts
index 75f5d07f0d..750108f62d 100644
--- a/packages/sheets-hyper-link/src/controllers/set-range.controller.ts
+++ b/packages/sheets-hyper-link/src/controllers/set-range.controller.ts
@@ -98,7 +98,7 @@ export class SheetHyperLinkSetRangeController extends Disposable {
const redos: IMutationInfo[] = [];
const undos: IMutationInfo[] = [];
const selection = this._selectionManagerService.getCurrentLastSelection();
- const target = getSheetCommandTarget(this._univerInstanceService);
+ const target = getSheetCommandTarget(this._univerInstanceService, command.params);
if (selection && target) {
const { unitId, subUnitId } = target;
Range.foreach(selection.range, (row, col) => {
diff --git a/packages/sheets-table/src/commands/commands/sheet-table-row-col.command.ts b/packages/sheets-table/src/commands/commands/sheet-table-row-col.command.ts
index b2c4ad7436..fa1dee5e37 100644
--- a/packages/sheets-table/src/commands/commands/sheet-table-row-col.command.ts
+++ b/packages/sheets-table/src/commands/commands/sheet-table-row-col.command.ts
@@ -356,7 +356,7 @@ export const SheetTableRemoveRowCommand: ICommand<ISheetTableRowColOperationComm
}
const univerInstanceService = accessor.get(IUniverInstanceService);
- const target = getSheetCommandTarget(univerInstanceService);
+ const target = getSheetCommandTarget(univerInstanceService, params);
if (!target) {
return false;
}
@@ -460,7 +460,7 @@ export const SheetTableRemoveColCommand: ICommand<ISheetTableRowColOperationComm
return false;
}
const univerInstanceService = accessor.get(IUniverInstanceService);
- const target = getSheetCommandTarget(univerInstanceService);
+ const target = getSheetCommandTarget(univerInstanceService, params);
if (!target) {
return false;
}
diff --git a/packages/sheets-table/src/controllers/sheet-table-ref-range.controller.ts b/packages/sheets-table/src/controllers/sheet-table-ref-range.controller.ts
index afae5a9a54..cea810a7a9 100644
--- a/packages/sheets-table/src/controllers/sheet-table-ref-range.controller.ts
+++ b/packages/sheets-table/src/controllers/sheet-table-ref-range.controller.ts
@@ -71,7 +71,7 @@ export class SheetTableRefRangeController extends Disposable {
const undos: IMutationInfo[] = [];
const redos: IMutationInfo[] = [];
- const target = getSheetCommandTarget(this._univerInstanceService);
+ const target = getSheetCommandTarget(this._univerInstanceService, insertParams);
if (!target) {
return { undos, redos };
}
@@ -129,7 +129,7 @@ export class SheetTableRefRangeController extends Disposable {
const undos: IMutationInfo[] = [];
const redos: IMutationInfo[] = [];
- const target = getSheetCommandTarget(this._univerInstanceService);
+ const target = getSheetCommandTarget(this._univerInstanceService, insertParams);
if (!target) {
return { undos, redos };
}
diff --git a/packages/sheets-ui/src/controllers/auto-width.controller.ts b/packages/sheets-ui/src/controllers/auto-width.controller.ts
index 3b4bd824cf..8bb53f5ebb 100644
--- a/packages/sheets-ui/src/controllers/auto-width.controller.ts
+++ b/packages/sheets-ui/src/controllers/auto-width.controller.ts
@@ -65,7 +65,7 @@ export class AutoWidthController extends Disposable {
const defaultValue = { redos: [], undos: [] };
const { _univerInstanceService: univerInstanceService } = this;
- const target = getSheetCommandTarget(univerInstanceService);
+ const target = getSheetCommandTarget(univerInstanceService, params);
if (!target) return defaultValue;
const { unitId, subUnitId, worksheet } = target;
diff --git a/packages/sheets-ui/src/controllers/permission/sheet-permission-check-ui.controller.ts b/packages/sheets-ui/src/controllers/permission/sheet-permission-check-ui.controller.ts
index c5ebb1c8e7..f87fa84b83 100644
--- a/packages/sheets-ui/src/controllers/permission/sheet-permission-check-ui.controller.ts
+++ b/packages/sheets-ui/src/controllers/permission/sheet-permission-check-ui.controller.ts
@@ -230,7 +230,7 @@ export class SheetPermissionCheckUIController extends Disposable {
const { targetRange } = params;
- const target = getSheetCommandTarget(this._univerInstanceService);
+ const target = getSheetCommandTarget(this._univerInstanceService, params);
if (!target) {
return false;
}
diff --git a/packages/sheets/src/commands/commands/register-range-theme.command.ts b/packages/sheets/src/commands/commands/register-range-theme.command.ts
index 2f21d2b722..54e13119a9 100644
--- a/packages/sheets/src/commands/commands/register-range-theme.command.ts
+++ b/packages/sheets/src/commands/commands/register-range-theme.command.ts
@@ -38,7 +38,7 @@ export const RegisterWorksheetRangeThemeStyleCommand: ICommand<IRegisterWorkshee
const univerInstanceService = accessor.get(IUniverInstanceService);
const commandService = accessor.get(ICommandService);
const undoRedoService = accessor.get(IUndoRedoService);
- const target = getSheetCommandTarget(univerInstanceService);
+ const target = getSheetCommandTarget(univerInstanceService, params);
if (!target) return false;
const redoParam = {
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 f7defbb169..e56b5be4b4 100644
--- a/packages/sheets/src/commands/commands/remove-row-col.command.ts
+++ b/packages/sheets/src/commands/commands/remove-row-col.command.ts
@@ -209,17 +209,17 @@ export const RemoveColCommandId = 'sheet.command.remove-col';
export const RemoveColByRangeCommand: ICommand<IRemoveColByRangeCommandParams> = {
type: CommandType.COMMAND,
id: 'sheet.command.remove-col-by-range',
- handler: (accessor, parmas) => {
- if (!parmas) {
+ handler: (accessor, params) => {
+ if (!params) {
return false;
}
const univerInstanceService = accessor.get(IUniverInstanceService);
- const target = getSheetCommandTarget(univerInstanceService, parmas);
+ const target = getSheetCommandTarget(univerInstanceService, params);
if (!target) return false;
const { workbook, worksheet } = target;
const sheetInterceptorService = accessor.get(SheetInterceptorService);
- const { range, unitId, subUnitId } = parmas;
+ const { range, unitId, subUnitId } = params;
// col count
const removeColParams: IRemoveColMutationParams = {
unitId,
diff --git a/packages/sheets/src/commands/commands/set-gridlines-color.command.ts b/packages/sheets/src/commands/commands/set-gridlines-color.command.ts
index 18bf427600..c3e6134923 100644
--- a/packages/sheets/src/commands/commands/set-gridlines-color.command.ts
+++ b/packages/sheets/src/commands/commands/set-gridlines-color.command.ts
@@ -34,7 +34,7 @@ export const SetGridlinesColorCommand: ICommand = {
const undoRedoService = accessor.get(IUndoRedoService);
const univerInstanceService = accessor.get(IUniverInstanceService);
- const target = getSheetCommandTarget(univerInstanceService);
+ const target = getSheetCommandTarget(univerInstanceService, params);
if (!target) return false;
const { worksheet } = target;
diff --git a/packages/sheets/src/commands/commands/set-worksheet-show.command.ts b/packages/sheets/src/commands/commands/set-worksheet-show.command.ts
index 8b3a5fea2c..fbe5078465 100644
--- a/packages/sheets/src/commands/commands/set-worksheet-show.command.ts
+++ b/packages/sheets/src/commands/commands/set-worksheet-show.command.ts
@@ -14,11 +14,10 @@
* limitations under the License.
*/
-import type { IAccessor, ICommand, Workbook } from '@univerjs/core';
+import type { IAccessor, ICommand } from '@univerjs/core';
import type { ISetWorksheetHideMutationParams } from '../mutations/set-worksheet-hide.mutation';
-
import type { ISetWorksheetActiveOperationParams } from '../operations/set-worksheet-active.operation';
-import { BooleanNumber, CommandType, ICommandService, IUndoRedoService, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
+import { BooleanNumber, CommandType, ICommandService, IUndoRedoService, IUniverInstanceService } from '@univerjs/core';
import { SetWorksheetHideMutation, SetWorksheetHideMutationFactory } from '../mutations/set-worksheet-hide.mutation';
import {
SetWorksheetActiveOperation,
@@ -36,23 +35,16 @@ export const SetWorksheetShowCommand: ICommand = {
id: 'sheet.command.set-worksheet-show',
handler: (accessor: IAccessor, params: ISetWorksheetShowCommandParams) => {
- const { unitId, subUnitId } = params;
-
- const commandService = accessor.get(ICommandService);
- const undoRedoService = accessor.get(IUndoRedoService);
- const univerInstanceService = accessor.get(IUniverInstanceService);
-
- const target = getSheetCommandTarget(accessor.get(IUniverInstanceService));
+ const target = getSheetCommandTarget(accessor.get(IUniverInstanceService), params);
if (!target) return false;
- const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
- if (!workbook) return false;
- const worksheet = workbook.getSheetBySheetId(subUnitId);
- if (!worksheet) return false;
-
+ const { unitId, subUnitId, worksheet } = target;
const hidden = worksheet.getConfig().hidden;
if (hidden === BooleanNumber.FALSE) return false;
+ const commandService = accessor.get(ICommandService);
+ const undoRedoService = accessor.get(IUndoRedoService);
+
const redoMutationParams: ISetWorksheetHideMutationParams = {
unitId,
subUnitId,
diff --git a/packages/sheets/src/commands/commands/split-text-to-columns.command.ts b/packages/sheets/src/commands/commands/split-text-to-columns.command.ts
index 7df6b09c91..aa8013c81f 100644
--- a/packages/sheets/src/commands/commands/split-text-to-columns.command.ts
+++ b/packages/sheets/src/commands/commands/split-text-to-columns.command.ts
@@ -14,11 +14,11 @@
* limitations under the License.
*/
-import type { IAccessor, ICellData, IRange, Nullable, Workbook } from '@univerjs/core';
+import type { IAccessor, ICellData, IRange, Nullable } from '@univerjs/core';
import type { IInsertColMutationParams, IRemoveColMutationParams } from '../../basics';
import type { SplitDelimiterEnum } from '../../basics/split-range-text';
import type { ISetRangeValuesMutationParams } from '../mutations/set-range-values.mutation';
-import { CommandType, ICommandService, IUndoRedoService, IUniverInstanceService, ObjectMatrix, Range, sequenceExecute, UniverInstanceType } from '@univerjs/core';
+import { CommandType, ICommandService, IUndoRedoService, IUniverInstanceService, ObjectMatrix, Range, sequenceExecute } from '@univerjs/core';
import { splitRangeText } from '../../basics/split-range-text';
import { InsertColMutation, InsertColMutationUndoFactory } from '../mutations/insert-row-col.mutation';
import { RemoveColMutation } from '../mutations/remove-row-col.mutation';
@@ -39,20 +39,11 @@ export const SplitTextToColumnsCommand = {
id: 'sheet.command.split-text-to-columns',
// eslint-disable-next-line max-lines-per-function
handler: (accessor: IAccessor, params: ISplitTextToColumnsCommandParams) => {
- const { unitId, subUnitId, range, delimiter, customDelimiter, treatMultipleDelimitersAsOne } = params;
-
- const commandService = accessor.get(ICommandService);
-
- const univerInstanceService = accessor.get(IUniverInstanceService);
- const undoRedoService = accessor.get(IUndoRedoService);
-
- const target = getSheetCommandTarget(accessor.get(IUniverInstanceService));
+ const target = getSheetCommandTarget(accessor.get(IUniverInstanceService), params);
if (!target) return false;
- const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
- if (!workbook) return false;
- const worksheet = workbook.getSheetBySheetId(subUnitId);
- if (!worksheet) return false;
+ const { unitId, subUnitId, worksheet } = target;
+ const { range, delimiter, customDelimiter, treatMultipleDelimitersAsOne } = params;
const { lastRow, rs, maxLength } = splitRangeText(worksheet, range, delimiter, customDelimiter, treatMultipleDelimitersAsOne);
const maxColumn = worksheet.getColumnCount();
const { startColumn } = Range.transformRange(range, worksheet);
@@ -61,6 +52,8 @@ export const SplitTextToColumnsCommand = {
return false;
}
+ const commandService = accessor.get(ICommandService);
+ const undoRedoService = accessor.get(IUndoRedoService);
const redoMutations = [];
const undoMutations = [];
diff --git a/packages/sheets/src/commands/commands/toggle-gridlines.command.ts b/packages/sheets/src/commands/commands/toggle-gridlines.command.ts
index 733459b509..ae6ae45509 100644
--- a/packages/sheets/src/commands/commands/toggle-gridlines.command.ts
+++ b/packages/sheets/src/commands/commands/toggle-gridlines.command.ts
@@ -32,9 +32,8 @@ export const ToggleGridlinesCommand: ICommand = {
handler: (accessor: IAccessor, params?: IToggleGridlinesCommandParams) => {
const commandService = accessor.get(ICommandService);
const undoRedoService = accessor.get(IUndoRedoService);
- const univerInstanceService = accessor.get(IUniverInstanceService);
- const target = getSheetCommandTarget(univerInstanceService);
+ const target = getSheetCommandTarget(accessor.get(IUniverInstanceService), params);
if (!target) return false;
const { worksheet } = target;
diff --git a/packages/sheets/src/commands/commands/unregister-range-theme.command.ts b/packages/sheets/src/commands/commands/unregister-range-theme.command.ts
index a7a1a2d11f..db4800e1b9 100644
--- a/packages/sheets/src/commands/commands/unregister-range-theme.command.ts
+++ b/packages/sheets/src/commands/commands/unregister-range-theme.command.ts
@@ -16,7 +16,6 @@
import type { ICommand } from '@univerjs/core';
import { CommandType, ICommandService, IUndoRedoService, IUniverInstanceService } from '@univerjs/core';
-
import { SheetRangeThemeModel } from '../../model/range-theme-model';
import { getSheetCommandTarget } from '../commands/utils/target-util';
import { RegisterWorksheetRangeThemeStyleMutation } from '../mutations/register-range-theme.mutation';
@@ -31,16 +30,15 @@ export const UnregisterWorksheetRangeThemeStyleCommand: ICommand<IUnregisterWork
id: 'sheet.command.unregister-worksheet-range-theme-style',
type: CommandType.COMMAND,
handler: (accessor, params) => {
- if (!params) {
- return false;
- }
- const { unitId, themeName } = params;
- const univerInstanceService = accessor.get(IUniverInstanceService);
+ if (!params) return false;
+
+ const target = getSheetCommandTarget(accessor.get(IUniverInstanceService), params);
+ if (!target) return false;
+
const commandService = accessor.get(ICommandService);
const undoRedoService = accessor.get(IUndoRedoService);
const sheetRangeThemeModel = accessor.get(SheetRangeThemeModel);
- const target = getSheetCommandTarget(univerInstanceService);
- if (!target) return false;
+ const { unitId, themeName } = params;
const redoParam = {
unitId,
@@ -51,6 +49,7 @@ export const UnregisterWorksheetRangeThemeStyleCommand: ICommand<IUnregisterWork
themeName,
rangeThemeStyleJson: sheetRangeThemeModel.getRangeThemeStyle(unitId, themeName)?.toJson(),
};
+
const result = commandService.syncExecuteCommand(RegisterWorksheetRangeThemeStyleMutation.id, params);
if (result) {
undoRedoService.pushUndoRedo({
@@ -58,7 +57,9 @@ export const UnregisterWorksheetRangeThemeStyleCommand: ICommand<IUnregisterWork
undoMutations: [{ id: RegisterWorksheetRangeThemeStyleMutation.id, params: undoParam }],
redoMutations: [{ id: UnregisterWorksheetRangeThemeStyleMutation.id, params: redoParam }],
});
+ return true;
}
- return true;
+
+ return false;
},
};
diff --git a/packages/sheets/src/commands/mutations/add-worksheet-range-theme.mutation.ts b/packages/sheets/src/commands/mutations/add-worksheet-range-theme.mutation.ts
index 403f43c63f..5bdcbbee40 100644
--- a/packages/sheets/src/commands/mutations/add-worksheet-range-theme.mutation.ts
+++ b/packages/sheets/src/commands/mutations/add-worksheet-range-theme.mutation.ts
@@ -24,12 +24,12 @@ export const SetWorksheetRangeThemeStyleMutation: IMutation<IWorksheetRangeTheme
id: 'sheet.mutation.set-worksheet-range-theme-style',
type: CommandType.MUTATION,
handler: (accessor, params) => {
- const { unitId, subUnitId, range, themeName } = params;
- const univerInstanceService = accessor.get(IUniverInstanceService);
- const target = getSheetCommandTarget(univerInstanceService);
- const sheetRangeThemeModel = accessor.get(SheetRangeThemeModel);
+ const target = getSheetCommandTarget(accessor.get(IUniverInstanceService), params);
if (!target) return false;
+ const sheetRangeThemeModel = accessor.get(SheetRangeThemeModel);
+ const { unitId, subUnitId, range, themeName } = params;
+
sheetRangeThemeModel.registerRangeThemeRule(themeName, { range, unitId, subUnitId });
return true;
},
diff --git a/packages/sheets/src/commands/mutations/delete-worksheet-range-theme.mutation.ts b/packages/sheets/src/commands/mutations/delete-worksheet-range-theme.mutation.ts
index 37a50ab882..11b0562cb8 100644
--- a/packages/sheets/src/commands/mutations/delete-worksheet-range-theme.mutation.ts
+++ b/packages/sheets/src/commands/mutations/delete-worksheet-range-theme.mutation.ts
@@ -24,12 +24,12 @@ export const DeleteWorksheetRangeThemeStyleMutation: IMutation<IWorksheetRangeTh
id: 'sheet.mutation.remove-worksheet-range-theme-style',
type: CommandType.MUTATION,
handler: (accessor, params) => {
- const { unitId, subUnitId, range, themeName } = params;
- const univerInstanceService = accessor.get(IUniverInstanceService);
- const target = getSheetCommandTarget(univerInstanceService);
- const sheetRangeThemeModel = accessor.get(SheetRangeThemeModel);
+ const target = getSheetCommandTarget(accessor.get(IUniverInstanceService), params);
if (!target) return false;
+ const sheetRangeThemeModel = accessor.get(SheetRangeThemeModel);
+ const { unitId, subUnitId, range, themeName } = params;
+
sheetRangeThemeModel.removeRangeThemeRule(themeName, { range, unitId, subUnitId });
return true;
},
diff --git a/packages/sheets/src/commands/mutations/register-range-theme.mutation.ts b/packages/sheets/src/commands/mutations/register-range-theme.mutation.ts
index 688fcf988e..4caef8f7d5 100644
--- a/packages/sheets/src/commands/mutations/register-range-theme.mutation.ts
+++ b/packages/sheets/src/commands/mutations/register-range-theme.mutation.ts
@@ -31,12 +31,12 @@ export const RegisterWorksheetRangeThemeStyleMutation: IMutation<IRegisterWorksh
id: 'sheet.mutation.register-worksheet-range-theme-style',
type: CommandType.MUTATION,
handler: (accessor, params) => {
- const { unitId, rangeThemeStyleJson, themeName } = params;
- const univerInstanceService = accessor.get(IUniverInstanceService);
- const target = getSheetCommandTarget(univerInstanceService);
- const sheetRangeThemeModel = accessor.get(SheetRangeThemeModel);
+ const target = getSheetCommandTarget(accessor.get(IUniverInstanceService), params);
if (!target) return false;
+ const sheetRangeThemeModel = accessor.get(SheetRangeThemeModel);
+ const { unitId, rangeThemeStyleJson, themeName } = params;
+
const rangeThemeStyle = new RangeThemeStyle(themeName, rangeThemeStyleJson);
sheetRangeThemeModel.registerRangeThemeStyle(unitId, rangeThemeStyle);
return true;
diff --git a/packages/sheets/src/commands/mutations/set-worksheet-default-style.mutation.ts b/packages/sheets/src/commands/mutations/set-worksheet-default-style.mutation.ts
index 017d9c7878..9b38af6ce0 100644
--- a/packages/sheets/src/commands/mutations/set-worksheet-default-style.mutation.ts
+++ b/packages/sheets/src/commands/mutations/set-worksheet-default-style.mutation.ts
@@ -28,15 +28,11 @@ export const SetWorksheetDefaultStyleMutation: IMutation<ISetWorksheetDefaultSty
id: 'sheet.mutation.set-worksheet-default-style',
type: CommandType.MUTATION,
handler: (accessor, params) => {
- const { defaultStyle } = params;
- const univerInstanceService = accessor.get(IUniverInstanceService);
- const target = getSheetCommandTarget(univerInstanceService);
+ const target = getSheetCommandTarget(accessor.get(IUniverInstanceService), params);
if (!target) return false;
const { worksheet } = target;
- if (!worksheet) {
- return false;
- }
+ const { defaultStyle } = params;
worksheet.setDefaultCellStyle(defaultStyle);
return true;
},
diff --git a/packages/sheets/src/commands/mutations/unregister-range-theme-style.mutation.ts b/packages/sheets/src/commands/mutations/unregister-range-theme-style.mutation.ts
index 91e35ae78a..648298bb1e 100644
--- a/packages/sheets/src/commands/mutations/unregister-range-theme-style.mutation.ts
+++ b/packages/sheets/src/commands/mutations/unregister-range-theme-style.mutation.ts
@@ -28,12 +28,12 @@ export const UnregisterWorksheetRangeThemeStyleMutation: IMutation<IUnregisterWo
id: 'sheet.mutation.unregister-worksheet-range-theme-style',
type: CommandType.MUTATION,
handler: (accessor, params) => {
- const { unitId, themeName } = params;
- const univerInstanceService = accessor.get(IUniverInstanceService);
- const target = getSheetCommandTarget(univerInstanceService);
- const sheetRangeThemeModel = accessor.get(SheetRangeThemeModel);
+ const target = getSheetCommandTarget(accessor.get(IUniverInstanceService), params);
if (!target) return false;
+ const sheetRangeThemeModel = accessor.get(SheetRangeThemeModel);
+ const { unitId, themeName } = params;
+
sheetRangeThemeModel.unregisterRangeThemeStyle(unitId, themeName);
return true;
},
diff --git a/packages/sheets/src/controllers/permission/sheet-permission-check.controller.ts b/packages/sheets/src/controllers/permission/sheet-permission-check.controller.ts
index 0d330c18bd..7dfd12c4e3 100644
--- a/packages/sheets/src/controllers/permission/sheet-permission-check.controller.ts
+++ b/packages/sheets/src/controllers/permission/sheet-permission-check.controller.ts
@@ -361,42 +361,33 @@ export class SheetPermissionCheckController extends Disposable {
}
public permissionCheckWithRanges(permissionTypes: IPermissionTypes, selectionRanges?: IRange[], unitId?: string, subUnitId?: string) {
- const target = getSheetCommandTarget(this._univerInstanceService);
- if (!target) {
- return false;
- }
- const { workbook, worksheet } = target;
- if (!unitId) {
- unitId = workbook.getUnitId();
- }
- if (!subUnitId) {
- subUnitId = worksheet.getSheetId();
- }
+ const target = getSheetCommandTarget(this._univerInstanceService, { unitId, subUnitId });
+ if (!target) return false;
+
const ranges = selectionRanges ?? this._selectionManagerService.getCurrentSelections()?.map((selection) => {
return selection.range;
});
+ if (!ranges) return false;
- if (!ranges) {
- return false;
- }
-
+ const { unitId: _unitId, subUnitId: _subUnitId } = target;
const { workbookTypes, worksheetTypes, rangeTypes } = permissionTypes;
+
const permissionIds = [];
if (workbookTypes) {
- permissionIds.push(...workbookTypes.map((F) => new F(unitId).id));
+ permissionIds.push(...workbookTypes.map((F) => new F(_unitId).id));
}
if (worksheetTypes) {
- permissionIds.push(...worksheetTypes.map((F) => new F(unitId, subUnitId).id));
+ permissionIds.push(...worksheetTypes.map((F) => new F(_unitId, _subUnitId).id));
}
if (rangeTypes) {
- this._rangeProtectionRuleModel.getSubunitRuleList(unitId, subUnitId).forEach((rule) => {
+ this._rangeProtectionRuleModel.getSubunitRuleList(_unitId, _subUnitId).forEach((rule) => {
const overlap = ranges.some((range) => {
return rule.ranges.some((r) => {
return Rectangle.intersects(r, range);
});
});
if (overlap) {
- permissionIds.push(...rangeTypes.map((F) => new F(unitId, subUnitId, rule.permissionId).id));
+ permissionIds.push(...rangeTypes.map((F) => new F(_unitId, _subUnitId, rule.permissionId).id));
}
});
}
@@ -409,17 +400,18 @@ export class SheetPermissionCheckController extends Disposable {
}
private _permissionCheckByMoveCommand(params: IMoveRowsCommandParams | IMoveColsCommandParams) {
- const target = getSheetCommandTarget(this._univerInstanceService);
- if (!target) {
- return false;
- }
+ const target = getSheetCommandTarget(this._univerInstanceService, params);
+ if (!target) return false;
+
const { worksheet, unitId, subUnitId } = target;
+
const toRange = params.toRange;
if (toRange.endRow === worksheet.getRowCount() - 1) {
toRange.endColumn = toRange.startColumn;
} else {
toRange.endRow = toRange.startRow;
}
+
const permissionLapRanges = this._rangeProtectionRuleModel.getSubunitRuleList(unitId, subUnitId).reduce((p, c) => {
return [...p, ...c.ranges];
}, [] as IRange[]).filter((range) => {
@@ -429,6 +421,7 @@ export class SheetPermissionCheckController extends Disposable {
if (permissionLapRanges.length > 0) {
return false;
}
+
permissionLapRanges.forEach((range) => {
for (let row = range.startRow; row <= range.endRow; row++) {
for (let col = range.startColumn; col <= range.endColumn; col++) {
@@ -562,18 +555,18 @@ export class SheetPermissionCheckController extends Disposable {
}
}
if (range) {
- const target = getSheetCommandTarget(this._univerInstanceService);
- if (!target) {
- return false;
- }
- const unitId = params.unitId || target.unitId;
- const subunitId = params.subUnitId || target.subUnitId;
- const permissionList = this._rangeProtectionRuleModel.getSubunitRuleList(unitId, subunitId).filter((rule) => {
+ const target = getSheetCommandTarget(this._univerInstanceService, params);
+ if (!target) return false;
+
+ const { unitId, subUnitId } = target;
+
+ const permissionList = this._rangeProtectionRuleModel.getSubunitRuleList(unitId, subUnitId).filter((rule) => {
return rule.ranges.some((ruleRange) => {
return Rectangle.intersects(ruleRange, range);
});
});
- const permissionIds = permissionList.map((rule) => new RangeProtectionPermissionEditPoint(unitId, subunitId, rule.permissionId).id);
+ const permissionIds = permissionList.map((rule) => new RangeProtectionPermissionEditPoint(unitId, subUnitId, rule.permissionId).id);
+
const editPermission = this._permissionService.composePermission(permissionIds).every((permission) => permission.value);
if (!editPermission) {
return false;