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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(sheets-ui): preserve active range when cycling selections (#8142)
白熱35b5f2a233a4
diff --git a/packages/sheets-ui/src/commands/commands/__tests__/set-selection.command.spec.ts b/packages/sheets-ui/src/commands/commands/__tests__/set-selection.command.spec.tsindex 9c322bee09..c70143f722 100644--- a/packages/sheets-ui/src/commands/commands/__tests__/set-selection.command.spec.ts+++ b/packages/sheets-ui/src/commands/commands/__tests__/set-selection.command.spec.ts@@ -25,7 +25,6 @@ import {RANGE_TYPE,UniverInstanceType,} from '@univerjs/core';-import { IRenderManagerService } from '@univerjs/engine-render';import {IRefSelectionsService,REF_SELECTIONS_ENABLED,@@ -50,7 +49,6 @@ import type {} from '../set-selection.command';import { SHEETS_UI_PLUGIN_CONFIG_KEY } from '../../../config/config';import { SelectAllService } from '../../../services/select-all/select-all.service';-import { ISheetSelectionRenderService } from '../../../services/selection/base-selection-render.service';import {ExpandSelectionCommand,JumpOver,@@ -1098,97 +1096,38 @@ describe('Test commands used for change selections', () => {expectSelectionToBe(0, 1, 0, 1);});- it('should move active cell inside multi-selections and wrap to the next selection', async () => {- const refreshSelectionMoveEnd = vi.fn();- const renderManagerService = get(IRenderManagerService);- vi.spyOn(renderManagerService, 'getRenderUnitById').mockReturnValue({- with: (identifier: unknown) => {- if (identifier === ISheetSelectionRenderService) {- return { refreshSelectionMoveEnd };- }-- return null;- },- } as never);-- selectionManagerService.setSelections([- {- range: { startRow: 0, startColumn: 0, endRow: 0, endColumn: 1, rangeType: RANGE_TYPE.NORMAL },- primary: {- startRow: 0,- startColumn: 0,- endRow: 0,- endColumn: 0,- actualRow: 0,- actualColumn: 0,- isMerged: false,- isMergedMainCell: false,- },- style: null,- },- {- range: { startRow: 1, startColumn: 0, endRow: 1, endColumn: 1, rangeType: RANGE_TYPE.NORMAL },- primary: {- startRow: 1,- startColumn: 0,- endRow: 1,- endColumn: 0,- actualRow: 1,- actualColumn: 0,- isMerged: false,- isMergedMainCell: false,- },- style: null,- },- ]);-- await commandService.executeCommand<IMoveSelectionEnterAndTabCommandParams>(MoveSelectionEnterAndTabCommand.id, {- direction: Direction.RIGHT,- keycode: KeyCode.TAB,- });-- let activeSelection = selectionManagerService.getCurrentSelections().find((selection) => selection.primary);- expect(activeSelection?.range).toEqual({- startRow: 0,- startColumn: 0,- endRow: 0,- endColumn: 1,- rangeType: RANGE_TYPE.NORMAL,- });- expect(activeSelection?.primary?.startColumn).toBe(1);-- await commandService.executeCommand<IMoveSelectionEnterAndTabCommandParams>(MoveSelectionEnterAndTabCommand.id, {- direction: Direction.RIGHT,- keycode: KeyCode.TAB,- });-- activeSelection = selectionManagerService.getCurrentSelections().find((selection) => selection.primary);- expect(activeSelection?.range).toEqual({- startRow: 1,- startColumn: 0,- endRow: 1,- endColumn: 1,- rangeType: RANGE_TYPE.NORMAL,- });- expect(activeSelection?.primary?.startRow).toBe(1);- expect(activeSelection?.primary?.startColumn).toBe(0);-- await commandService.executeCommand<IMoveSelectionEnterAndTabCommandParams>(MoveSelectionEnterAndTabCommand.id, {- direction: Direction.LEFT,- keycode: KeyCode.TAB,- });-- activeSelection = selectionManagerService.getCurrentSelections().find((selection) => selection.primary);- expect(activeSelection?.range).toEqual({- startRow: 0,- startColumn: 0,- endRow: 0,- endColumn: 1,+ it.each([+ { name: 'Tab', keycode: KeyCode.TAB, direction: Direction.RIGHT, reverse: Direction.LEFT, vertical: false },+ { name: 'Enter', keycode: KeyCode.ENTER, direction: Direction.DOWN, reverse: Direction.UP, vertical: true },+ ])('cycles three ranges in both directions with $name and keeps the editing target current', async ({ keycode, direction, reverse, vertical }) => {+ const worksheet = get(IUniverInstanceService).getCurrentUnitOfType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getActiveSheet();+ const ranges = [0, 6, 12].map((start) => ({+ startRow: start,+ endRow: start + 1,+ startColumn: start,+ endColumn: start + 1,rangeType: RANGE_TYPE.NORMAL,- });- expect(activeSelection?.primary?.startRow).toBe(0);- expect(activeSelection?.primary?.startColumn).toBe(1);- expect(refreshSelectionMoveEnd).toHaveBeenCalledTimes(3);+ }));+ selectionManagerService.setSelections(ranges.map((range, index) => ({+ range,+ primary: index === ranges.length - 1 ? worksheet.getCellInfoInMergeData(13, 13) : null,+ style: null,+ })));+ const offsets = vertical ? [[0, 0], [1, 0], [0, 1], [1, 1]] : [[0, 0], [0, 1], [1, 0], [1, 1]];+ const cells = [0, 6, 12].flatMap((start) => offsets.map(([row, column]) => [start + row, start + column]));++ for (const step of [direction, reverse]) {+ const expected = step === direction ? cells : [...cells.slice(0, -1).reverse(), cells[cells.length - 1]];+ for (const [row, column] of expected) {+ expect(await commandService.executeCommand(MoveSelectionEnterAndTabCommand.id, { direction: step, keycode })).toBe(true);+ const selections = selectionManagerService.getCurrentSelections();+ expect(selections.filter((selection) => selection.primary)).toHaveLength(1);+ expect(selections.map((selection) => selection.range)).toEqual(expect.arrayContaining(ranges));+ expect(selections).toHaveLength(ranges.length);+ expect(selectionManagerService.getCurrentLastSelection()?.primary).toMatchObject({ actualRow: row, actualColumn: column });+ expect(selectionManagerService.getCurrentLastSelectionPrimaryCell()).toMatchObject({ actualRow: row, actualColumn: column });+ }+ }});it('should remember tab origin for enter and stop at sheet boundaries', async () => {diff --git a/packages/sheets-ui/src/commands/commands/set-selection.command.ts b/packages/sheets-ui/src/commands/commands/set-selection.command.tsindex 20479fa56c..f8876c9a0c 100644--- a/packages/sheets-ui/src/commands/commands/set-selection.command.ts+++ b/packages/sheets-ui/src/commands/commands/set-selection.command.ts@@ -199,7 +199,7 @@ export const MoveSelectionEnterAndTabCommand: ICommand<IMoveSelectionEnterAndTabconst { direction, keycode } = params;const isReverse = direction === Direction.LEFT || direction === Direction.UP;- const selections = selectionsService.getCurrentSelections().concat();+ let selections = selectionsService.getCurrentSelections().concat();const currentSelectionIndex = selections.findIndex((s) => s.primary);const selection = selections[currentSelectionIndex];if (!selection) {@@ -333,6 +333,8 @@ export const MoveSelectionEnterAndTabCommand: ICommand<IMoveSelectionEnterAndTabif (isLastCell) {selections[currentSelectionIndex].primary = null;selections[nextSelectionIndex] = resultRange;+ // Keep the active range last for editing and permissions without changing the navigation cycle.+ selections = selections.slice(nextSelectionIndex + 1).concat(selections.slice(0, nextSelectionIndex + 1));selectionsService.setSelections(unitId, sheetId, [], SelectionMoveType.MOVE_END);} else {selections[currentSelectionIndex] = resultRange;diff --git a/packages/sheets-ui/src/controllers/permission/__tests__/sheet-permission-check-ui.controller.spec.ts b/packages/sheets-ui/src/controllers/permission/__tests__/sheet-permission-check-ui.controller.spec.tsindex f1d8d7ab41..723d22b7c2 100644--- a/packages/sheets-ui/src/controllers/permission/__tests__/sheet-permission-check-ui.controller.spec.ts+++ b/packages/sheets-ui/src/controllers/permission/__tests__/sheet-permission-check-ui.controller.spec.ts@@ -14,49 +14,78 @@* limitations under the License.*/-import type { ICommandInfo } from '@univerjs/core';+import type { ICommandInfo, IWorkbookData, Workbook } from '@univerjs/core';import {createInternalEditorID,+ Direction,DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,DOCS_NORMAL_EDITOR_UNIT_ID_KEY,+ DocumentDataModel,+ ICommandService,+ IContextService,+ Injector,+ IPermissionService,+ IUniverInstanceService,+ LocaleService,+ LocaleType,+ Univer,+ UniverInstanceType,} from '@univerjs/core';-import { InsertTextCommand } from '@univerjs/docs';-import { IMEInputCommand } from '@univerjs/docs-ui';+import { DocSelectionManagerService, DocStateChangeManagerService, DocStateEmitService, InsertTextCommand } from '@univerjs/docs';+import { EditorService, IEditorService, IMEInputCommand } from '@univerjs/docs-ui';+import { CanvasColorService, ICanvasColorService, IRenderManagerService, RenderManagerService, SHEET_VIEWPORT_KEY, Spreadsheet, Viewport } from '@univerjs/engine-render';+import { UnitObject } from '@univerjs/protocol';+import { EditStateEnum, RangeProtectionPermissionEditPoint, RangeProtectionRuleModel, SheetPermissionCheckController, SheetsSelectionsService, UniverSheetsPlugin, ViewStateEnum } from '@univerjs/sheets';+import { IDialogService, IPlatformService, IShortcutService, IUIRuntimeScopeService, KeyCode, PlatformService, ShortcutService, UIRuntimeScopeService } from '@univerjs/ui';import { EMPTY } from 'rxjs';-import { describe, expect, it, vi } from 'vitest';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { SheetCopyCommand, SheetCutCommand, SheetPasteCommand } from '../../../commands/commands/clipboard.command';+import { MoveSelectionEnterAndTabCommand } from '../../../commands/commands/set-selection.command';+import { SetActivateCellEditOperation } from '../../../commands/operations/activate-cell-edit.operation';import { SetCellEditVisibleOperation } from '../../../commands/operations/cell-edit.operation';+import { ScrollToRangeOperation } from '../../../commands/operations/scroll-to-range.operation';+import { SHEET_VIEW_KEY } from '../../../common/keys';+import enUS from '../../../locale/en-US';+import { EditorBridgeService, IEditorBridgeService } from '../../../services/editor-bridge.service';+import { CellEditorManagerService, ICellEditorManagerService } from '../../../services/editor/cell-editor-manager.service';+import { SheetCellEditorResizeService } from '../../../services/editor/cell-editor-resize.service';+import { ISheetSelectionRenderService } from '../../../services/selection/base-selection-render.service';+import { SheetSelectionRenderService } from '../../../services/selection/selection-render.service';+import { SheetSkeletonManagerService } from '../../../services/sheet-skeleton-manager.service';+import { ShortcutExperienceService } from '../../../services/shortcut-experience.service';+import { EditingRenderController } from '../../editor/editing.render-controller';+import { EditorBridgeRenderController } from '../../render-controllers/editor-bridge.render-controller';+import { SheetsScrollRenderController } from '../../render-controllers/scroll.render-controller';import { SheetPermissionCheckUIController } from '../sheet-permission-check-ui.controller';-type ControllerConstructorArgs = ConstructorParameters<typeof SheetPermissionCheckUIController>;--function createController() {+function createControllerTestBed() {let beforeCommandExecuted: ((commandInfo: ICommandInfo) => void) | undefined;const permissionCheckWithoutRange = vi.fn(() => false);const permissionCheckWithRanges = vi.fn(() => true);const blockExecuteWithoutPermission = vi.fn();- const controller = new SheetPermissionCheckUIController(- {- beforeCommandExecuted: vi.fn((listener: (commandInfo: ICommandInfo) => void) => {+ const injector = new Injector([+ [ICommandService, { useValue: {+ beforeCommandExecuted: (listener: (commandInfo: ICommandInfo) => void) => {beforeCommandExecuted = listener;return { dispose: vi.fn() };- }),- } as unknown as ControllerConstructorArgs[0],- { getShowComponents: vi.fn(() => true) } as unknown as ControllerConstructorArgs[1],- { open: vi.fn(), close: vi.fn() } as unknown as ControllerConstructorArgs[2],- {} as unknown as ControllerConstructorArgs[3],- { t: vi.fn((key: string) => `translated:${key}`) } as unknown as ControllerConstructorArgs[4],- { getContextValue: vi.fn(() => false) } as unknown as ControllerConstructorArgs[5],- {+ },+ } }],+ [IPermissionService, { useValue: { getShowComponents: () => true } }],+ [IDialogService, { useValue: { open: vi.fn(), close: vi.fn() } }],+ [RangeProtectionRuleModel, { useValue: {} }],+ [LocaleService, { useValue: { t: (key: string) => `translated:${key}` } }],+ [IContextService, { useValue: { getContextValue: () => false } }],+ [SheetPermissionCheckController, { useValue: {triggerPermissionUIEvent$: EMPTY,permissionCheckWithoutRange,permissionCheckWithRanges,blockExecuteWithoutPermission,- } as unknown as ControllerConstructorArgs[6]- );+ } }],+ [SheetPermissionCheckUIController],+ ]);return {- controller,+ injector,executeBefore: (commandInfo: ICommandInfo) => beforeCommandExecuted?.(commandInfo),permissionCheckWithoutRange,permissionCheckWithRanges,@@ -72,7 +101,8 @@ describe('SheetPermissionCheckUIController', () => {[IMEInputCommand.id, 'shape text editor', createInternalEditorID('SHAPE_TEXT')],[InsertTextCommand.id, 'slide text editor', createInternalEditorID('SLIDE_SHAPE_TEXT')],])('does not apply sheet permissions to %s input from a %s', (id, _, unitId) => {- const { controller, executeBefore, permissionCheckWithoutRange, blockExecuteWithoutPermission } = createController();+ const { injector, executeBefore, permissionCheckWithoutRange, blockExecuteWithoutPermission } = createControllerTestBed();+ injector.get(SheetPermissionCheckUIController);executeBefore({id,@@ -81,11 +111,12 @@ describe('SheetPermissionCheckUIController', () => {expect(permissionCheckWithoutRange).not.toHaveBeenCalled();expect(blockExecuteWithoutPermission).not.toHaveBeenCalled();- controller.dispose();+ injector.dispose();});it('checks the workbook identified by a cell editor visibility operation', () => {- const { controller, executeBefore, permissionCheckWithoutRange } = createController();+ const { injector, executeBefore, permissionCheckWithoutRange } = createControllerTestBed();+ injector.get(SheetPermissionCheckUIController);executeBefore({id: SetCellEditVisibleOperation.id,@@ -93,14 +124,15 @@ describe('SheetPermissionCheckUIController', () => {});expect(permissionCheckWithoutRange).toHaveBeenCalledWith(expect.any(Object), 'embedded-sheet');- controller.dispose();+ injector.dispose();});it.each([DOCS_NORMAL_EDITOR_UNIT_ID_KEY,DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,])('checks the current workbook when visibility is requested by internal sheet editor %s', (unitId) => {- const { controller, executeBefore, permissionCheckWithoutRange } = createController();+ const { injector, executeBefore, permissionCheckWithoutRange } = createControllerTestBed();+ injector.get(SheetPermissionCheckUIController);executeBefore({id: SetCellEditVisibleOperation.id,@@ -108,7 +140,7 @@ describe('SheetPermissionCheckUIController', () => {});expect(permissionCheckWithoutRange).toHaveBeenCalledWith(expect.any(Object), undefined);- controller.dispose();+ injector.dispose();});it.each([@@ -116,7 +148,8 @@ describe('SheetPermissionCheckUIController', () => {[IMEInputCommand.id, DOCS_NORMAL_EDITOR_UNIT_ID_KEY],[InsertTextCommand.id, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY],])('keeps applying sheet permissions to %s from %s', (id, unitId) => {- const { controller, executeBefore, permissionCheckWithoutRange, blockExecuteWithoutPermission } = createController();+ const { injector, executeBefore, permissionCheckWithoutRange, blockExecuteWithoutPermission } = createControllerTestBed();+ injector.get(SheetPermissionCheckUIController);executeBefore({id,@@ -125,7 +158,7 @@ describe('SheetPermissionCheckUIController', () => {expect(permissionCheckWithoutRange).toHaveBeenCalledOnce();expect(blockExecuteWithoutPermission).toHaveBeenCalledWith('translated:sheets-ui.permission.dialog.editErr');- controller.dispose();+ injector.dispose();});it.each([@@ -133,12 +166,133 @@ describe('SheetPermissionCheckUIController', () => {[SheetCutCommand.id, 'cut'],[SheetPasteCommand.id, 'paste'],])('does not preflight the global %s command before its multi-command implementation is selected', (id) => {- const { controller, executeBefore, permissionCheckWithRanges, blockExecuteWithoutPermission } = createController();+ const { injector, executeBefore, permissionCheckWithRanges, blockExecuteWithoutPermission } = createControllerTestBed();+ injector.get(SheetPermissionCheckUIController);executeBefore({ id });expect(permissionCheckWithRanges).not.toHaveBeenCalled();expect(blockExecuteWithoutPermission).not.toHaveBeenCalled();- controller.dispose();+ injector.dispose();+ });+});++describe('editing after navigating multiple ranges', () => {+ let univer: Univer;++ beforeEach(() => {+ // Happy DOM has no canvas backend; selection, editing, and permission logic remain real.+ vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockImplementation(function (this: HTMLCanvasElement) {+ return {+ canvas: this,+ setTransform: vi.fn(),+ clearRect: vi.fn(),+ measureText: (text: string) => ({ width: text.length * 7, fontBoundingBoxAscent: 10, fontBoundingBoxDescent: 4, actualBoundingBoxAscent: 10, actualBoundingBoxDescent: 4 }),+ } as unknown as CanvasRenderingContext2D;+ });+ univer = new Univer({ locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: enUS } });+ univer.registerPlugin(UniverSheetsPlugin);+ });++ afterEach(() => {+ univer.dispose();+ vi.restoreAllMocks();+ });++ it.each([+ { name: 'Tab', keycode: KeyCode.TAB, direction: Direction.RIGHT, reverse: false },+ { name: 'Enter', keycode: KeyCode.ENTER, direction: Direction.DOWN, reverse: false },+ { name: 'Shift+Tab', keycode: KeyCode.TAB, direction: Direction.LEFT, reverse: true },+ { name: 'Shift+Enter', keycode: KeyCode.ENTER, direction: Direction.UP, reverse: true },+ ])('writes to the new active cell after $name and still blocks protected targets', async ({ keycode, direction, reverse }) => {+ const injector = univer.__getInjector();+ const open = vi.fn();+ injector.add([IDialogService, { useValue: { open, close: vi.fn(), closeAll: vi.fn(), getDialogs$: () => EMPTY } }]);+ injector.add([ICanvasColorService, { useClass: CanvasColorService }]);+ injector.add([IRenderManagerService, { useClass: RenderManagerService }]);+ injector.add([DocSelectionManagerService]);+ injector.add([DocStateEmitService]);+ injector.add([DocStateChangeManagerService]);+ injector.add([IEditorService, { useClass: EditorService }]);+ injector.add([IEditorBridgeService, { useClass: EditorBridgeService }]);+ injector.add([ICellEditorManagerService, { useClass: CellEditorManagerService }]);+ injector.add([SheetCellEditorResizeService, { useValue: { resizeCellEditor: vi.fn() } as unknown as SheetCellEditorResizeService }]);+ injector.add([ShortcutExperienceService]);+ injector.add([IPlatformService, { useClass: PlatformService }]);+ injector.add([IShortcutService, { useClass: ShortcutService }]);+ injector.add([IUIRuntimeScopeService, { useClass: UIRuntimeScopeService }]);+ injector.add([SheetPermissionCheckUIController]);+ injector.add([EditingRenderController]);+ const workbook = univer.createUnit<IWorkbookData, Workbook>(UniverInstanceType.UNIVER_SHEET, {+ id: 'multi-edit',+ sheetOrder: ['sheet1'],+ sheets: { sheet1: { id: 'sheet1', rowCount: 20, columnCount: 20, cellData: {} } },+ });+ const worksheet = workbook.getActiveSheet();+ const renderManager = injector.get(IRenderManagerService);+ renderManager.registerRenderModule(UniverInstanceType.UNIVER_SHEET, [SheetSkeletonManagerService]);+ const render = renderManager.createRender(workbook.getUnitId());+ render.mainComponent = new Spreadsheet(SHEET_VIEW_KEY.MAIN);+ injector.createInstance(Viewport, SHEET_VIEWPORT_KEY.VIEW_MAIN, render.scene, { left: 0, top: 0, right: 0, bottom: 0 });+ render.with(SheetSkeletonManagerService).setCurrent({ sheetId: 'sheet1' });+ const commands = injector.get(ICommandService);+ [MoveSelectionEnterAndTabCommand, SetActivateCellEditOperation, SetCellEditVisibleOperation, ScrollToRangeOperation].forEach((command) => commands.registerCommand(command));+ renderManager.registerRenderModule(UniverInstanceType.UNIVER_SHEET, [SheetSelectionRenderService]);+ render.getInjector!().add([ISheetSelectionRenderService, { useValue: render.with(SheetSelectionRenderService) }]);+ renderManager.registerRenderModule(UniverInstanceType.UNIVER_SHEET, [EditorBridgeRenderController]);+ render.with(EditorBridgeRenderController);+ render.getInjector!().add([SheetsScrollRenderController, { useValue: { scrollToRange: vi.fn(() => true) } as unknown as SheetsScrollRenderController }]);+ injector.get(SheetPermissionCheckUIController);+ const editing = injector.get(EditingRenderController);+ const bridge = injector.get(IEditorBridgeService);+ const selections = injector.get(SheetsSelectionsService);+ const oldRow = reverse ? 3 : 4;+ const targetRow = reverse ? 1 : 0;+ worksheet.getCellMatrix().setValue(oldRow, oldRow, { v: 'old active cell' });+ worksheet.getCellMatrix().setValue(targetRow, targetRow, { v: 'new active cell' });+ selections.setSelections('multi-edit', 'sheet1', [+ { range: { startRow: 0, endRow: 1, startColumn: 0, endColumn: 1 }, primary: null, style: null },+ { range: { startRow: 3, endRow: 4, startColumn: 3, endColumn: 4 }, primary: worksheet.getCellInfoInMergeData(oldRow, oldRow), style: null },+ ]);+ injector.get(IUniverInstanceService).focusUnit('multi-edit');+ expect(await commands.executeCommand(MoveSelectionEnterAndTabCommand.id, { keycode, direction })).toBe(true);+ expect(bridge.getEditLocation()).toMatchObject({ row: targetRow, column: targetRow });+ expect(commands.syncExecuteCommand(SetCellEditVisibleOperation.id, { visible: true, unitId: 'multi-edit' })).toBe(true);+ bridge.changeEditorDirty(true);+ const input = injector.createInstance(DocumentDataModel, { id: 'input', body: { dataStream: 'typed value\r\n' }, documentStyle: {} });+ await editing.submitCellData(input);+ expect(worksheet.getCellRaw(targetRow, targetRow)?.v).toBe('typed value');+ expect(worksheet.getCellRaw(oldRow, oldRow)?.v).toBe('old active cell');+ expect(open).not.toHaveBeenCalled();++ const permissions = injector.get(IPermissionService);+ const editPoint = new RangeProtectionPermissionEditPoint('multi-edit', 'sheet1', 'protected-active');+ editPoint.value = false;+ permissions.addPermissionPoint(editPoint);+ const rules = injector.get(RangeProtectionRuleModel);+ const rule = {+ id: 'protected-active',+ permissionId: 'protected-active',+ unitId: 'multi-edit',+ subUnitId: 'sheet1',+ unitType: UnitObject.SelectRange,+ editState: EditStateEnum.OnlyMe,+ viewState: ViewStateEnum.OthersCanView,+ ranges: [{ startRow: 3, endRow: 4, startColumn: 3, endColumn: 4 }],+ };+ rules.addRule('multi-edit', 'sheet1', rule);+ expect(commands.syncExecuteCommand(SetCellEditVisibleOperation.id, { visible: true, unitId: 'multi-edit' })).toBe(true);+ bridge.changeEditorDirty(true);+ await editing.submitCellData(injector.createInstance(DocumentDataModel, { id: 'allowed-input', body: { dataStream: 'allowed value\r\n' }, documentStyle: {} }));+ expect(worksheet.getCellRaw(targetRow, targetRow)?.v).toBe('allowed value');+ expect(worksheet.getCellRaw(oldRow, oldRow)?.v).toBe('old active cell');+ expect(open).not.toHaveBeenCalled();++ rules.setRule('multi-edit', 'sheet1', rule.id, { ...rule, ranges: [{ startRow: 0, endRow: 1, startColumn: 0, endColumn: 1 }] });+ expect(commands.syncExecuteCommand(SetCellEditVisibleOperation.id, { visible: true, unitId: 'multi-edit' })).toBe(false);+ await editing.submitCellData(injector.createInstance(DocumentDataModel, { id: 'blocked-input', body: { dataStream: 'blocked value\r\n' }, documentStyle: {} }));+ expect(worksheet.getCellRaw(targetRow, targetRow)?.v).toBe('allowed value');+ expect(worksheet.getCellRaw(oldRow, oldRow)?.v).toBe('old active cell');+ expect(open).toHaveBeenCalled();});});