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
test: test col width and row height command (#210)
Wenzhao Hu2f2c3b9c8ce9
diff --git a/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts b/packages/base-sheets/src/Controller/BasicWorksheet.controller.tsindex 74256e7365..18c611b565 100644--- a/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts+++ b/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts@@ -46,17 +46,11 @@ import {} from '../commands/commands/set-style.command';import { SetTabColorCommand } from '../commands/commands/set-tab-color.command';import { SetWorksheetActivateCommand } from '../commands/commands/set-worksheet-activate.command';-import {- DeltaWorksheetColumnWidthCommand,- SetWorksheetColWidthCommand,-} from '../commands/commands/set-worksheet-col-width.command';+import { DeltaColumnWidthCommand, SetColWidthCommand } from '../commands/commands/set-worksheet-col-width.command';import { SetWorksheetHideCommand } from '../commands/commands/set-worksheet-hide.command';import { SetWorksheetNameCommand } from '../commands/commands/set-worksheet-name.command';import { SetWorksheetOrderCommand } from '../commands/commands/set-worksheet-order.command';-import {- DeltaWorksheetRowHeightCommand,- SetWorksheetRowHeightCommand,-} from '../commands/commands/set-worksheet-row-height.command';+import { DeltaRowHeightCommand, SetRowHeightCommand } from '../commands/commands/set-worksheet-row-height.command';import { SetWorksheetRowHideCommand } from '../commands/commands/set-worksheet-row-hide.command';import { SetWorksheetRowShowCommand } from '../commands/commands/set-worksheet-row-show.command';import { SetWorksheetShowCommand } from '../commands/commands/set-worksheet-show.command';@@ -130,9 +124,9 @@ export class BasicWorksheetController extends Disposable implements IDisposableRemoveColCommand,RemoveColMutation,- SetWorksheetColWidthCommand,+ SetColWidthCommand,SetWorksheetColWidthMutation,- SetWorksheetRowHeightCommand,+ SetRowHeightCommand,SetWorksheetRowHeightMutation,SetWorksheetRowHideCommand,SetWorksheetRowHideMutation,@@ -141,8 +135,8 @@ export class BasicWorksheetController extends Disposable implements IDisposableSetWorksheetOrderCommand,SetWorksheetOrderMutation,- DeltaWorksheetRowHeightCommand,- DeltaWorksheetColumnWidthCommand,+ DeltaRowHeightCommand,+ DeltaColumnWidthCommand,// #endregiondiff --git a/packages/base-sheets/src/Controller/header-move.controller.ts b/packages/base-sheets/src/Controller/header-move.controller.tsindex c71c21d6ac..04434141eb 100644--- a/packages/base-sheets/src/Controller/header-move.controller.ts+++ b/packages/base-sheets/src/Controller/header-move.controller.ts@@ -66,9 +66,13 @@ export class HeaderMoveController extends Disposable {private _scrollTimer!: ScrollTimer;- private _changeToColumn: number = -Infinity;+ private _changeFromColumn = -1;- private _changeToRow: number = -Infinity;+ private _changeFromRow = -1;++ private _changeToColumn = -1;++ private _changeToRow = -1;override dispose(): void {this._moveHelperBackgroundShape?.dispose();@@ -196,6 +200,12 @@ export class HeaderMoveController extends Disposable {skeleton);+ if (initialType === HEADER_MOVE_TYPE.ROW) {+ this._changeFromRow = row;+ } else {+ this._changeFromColumn = column;+ }+const matchSelectionData = this._checkInHeaderRange(initialType === HEADER_MOVE_TYPE.ROW ? row : column,initialType@@ -246,9 +256,13 @@ export class HeaderMoveController extends Disposable {console.log(this._changeToRow);// this._commandService.executeCommand();// alert(`moveColumnTo: ${this._changeToRow}`);++ this._changeToRow = this._changeFromRow = -1;} else {console.log(this._changeToColumn);// alert(`moveColumnTo: ${this._changeToColumn}`);++ this._changeToColumn = this._changeFromColumn = -1;}});})@@ -368,7 +382,7 @@ export class HeaderMoveController extends Disposable {}private _checkInHeaderRange(rowOrColumn: number, type: HEADER_MOVE_TYPE = HEADER_MOVE_TYPE.ROW) {- const rangeDatas = this._selectionManagerService.getSelectionDatas();+ const rangeDatas = this._selectionManagerService.getSelections();const matchSelectionData = rangeDatas?.find((data) => {const range = data.range;diff --git a/packages/base-sheets/src/Controller/header-resize.controller.ts b/packages/base-sheets/src/Controller/header-resize.controller.tsindex d006886ded..54fc86cec6 100644--- a/packages/base-sheets/src/Controller/header-resize.controller.ts+++ b/packages/base-sheets/src/Controller/header-resize.controller.ts@@ -21,13 +21,10 @@ import { Inject } from '@wendellhu/redi';import { getCoordByOffset, getSheetObject, getTransformCoord, ISheetObjectParam } from '../Basics/component-tools';import { CANVAS_VIEW_KEY, SHEET_COMPONENT_HEADER_LAYER_INDEX } from '../Basics/Const/DEFAULT_SPREADSHEET_VIEW';import {- DeltaWorksheetColumnWidthCommand,- IDeltaWorksheetColumnWidthCommandParams,+ DeltaColumnWidthCommand,+ IDeltaColumnWidthCommandParams,} from '../commands/commands/set-worksheet-col-width.command';-import {- DeltaWorksheetRowHeightCommand,- IDeltaWorksheetRowHeightCommand,-} from '../commands/commands/set-worksheet-row-height.command';+import { DeltaRowHeightCommand, IDeltaRowHeightCommand } from '../commands/commands/set-worksheet-row-height.command';import { SelectionManagerService } from '../services/selection-manager.service';import { SheetSkeletonManagerService } from '../services/sheet-skeleton-manager.service';import {@@ -380,13 +377,10 @@ export class HeaderResizeController extends Disposable {this._resizeHelperShape = null;this._columnResizeRect?.hide();- this._commandService.executeCommand<IDeltaWorksheetColumnWidthCommandParams>(- DeltaWorksheetColumnWidthCommand.id,- {- deltaX: moveChangeX,- anchorCol: this._currentColumn,- }- );+ this._commandService.executeCommand<IDeltaColumnWidthCommandParams>(DeltaColumnWidthCommand.id, {+ deltaX: moveChangeX,+ anchorCol: this._currentColumn,+ });});});@@ -504,13 +498,10 @@ export class HeaderResizeController extends Disposable {this._resizeHelperShape = null;this._rowResizeRect?.hide();- this._commandService.executeCommand<IDeltaWorksheetRowHeightCommand>(- DeltaWorksheetRowHeightCommand.id,- {- deltaY: moveChangeY,- anchorRow: this._currentRow,- }- );+ this._commandService.executeCommand<IDeltaRowHeightCommand>(DeltaRowHeightCommand.id, {+ deltaY: moveChangeY,+ anchorRow: this._currentRow,+ });});});diff --git a/packages/base-sheets/src/commands/commands/__tests__/add-worksheet-merge.spec.ts b/packages/base-sheets/src/commands/commands/__tests__/add-worksheet-merge.command.spec.tssimilarity index 100%rename from packages/base-sheets/src/commands/commands/__tests__/add-worksheet-merge.spec.tsrename to packages/base-sheets/src/commands/commands/__tests__/add-worksheet-merge.command.spec.tsdiff --git a/packages/base-sheets/src/commands/commands/__tests__/clear-selection-command.spec.ts b/packages/base-sheets/src/commands/commands/__tests__/clear-selection.command.spec.tssimilarity index 100%rename from packages/base-sheets/src/commands/commands/__tests__/clear-selection-command.spec.tsrename to packages/base-sheets/src/commands/commands/__tests__/clear-selection.command.spec.tsdiff --git a/packages/base-sheets/src/commands/commands/__tests__/set-border-command.spec.ts b/packages/base-sheets/src/commands/commands/__tests__/set-border-command.spec.tsindex 03589bbebd..6d67645901 100644--- a/packages/base-sheets/src/commands/commands/__tests__/set-border-command.spec.ts+++ b/packages/base-sheets/src/commands/commands/__tests__/set-border-command.spec.ts@@ -49,7 +49,7 @@ describe('Test style commands', () => {});afterEach(() => {- // univer.dispose();+ univer.dispose();});describe('set border style', () => {diff --git a/packages/base-sheets/src/commands/commands/__tests__/set-col-width.command.spec.ts b/packages/base-sheets/src/commands/commands/__tests__/set-col-width.command.spec.tsnew file mode 100644index 0000000000..4673f06db9--- /dev/null+++ b/packages/base-sheets/src/commands/commands/__tests__/set-col-width.command.spec.ts@@ -0,0 +1,130 @@+/* eslint-disable no-magic-numbers */+import { ICommandService, ICurrentUniverService, RANGE_TYPE, RedoCommand, UndoCommand, Univer } from '@univerjs/core';+import { Injector } from '@wendellhu/redi';+import { afterEach, beforeEach, describe, expect, it } from 'vitest';++import { NORMAL_SELECTION_PLUGIN_NAME, SelectionManagerService } from '../../../services/selection-manager.service';+import { SetWorksheetColWidthMutation } from '../../mutations/set-worksheet-col-width.mutation';+import {+ DeltaColumnWidthCommand,+ IDeltaColumnWidthCommandParams,+ ISetColWidthCommandParams,+ SetColWidthCommand,+} from '../set-worksheet-col-width.command';+import { createCommandTestBed } from './create-command-test-bed';++describe('Test set col width commands', () => {+ let univer: Univer;+ let get: Injector['get'];+ let commandService: ICommandService;++ function getColumnWidth(col: number): number {+ const worksheet = get(ICurrentUniverService).getCurrentUniverSheetInstance().getWorkBook().getActiveSheet();+ return worksheet.getColumnWidth(col);+ }++ beforeEach(() => {+ const testBed = createCommandTestBed();+ univer = testBed.univer;+ get = testBed.get;++ commandService = get(ICommandService);+ commandService.registerCommand(DeltaColumnWidthCommand);+ commandService.registerCommand(SetColWidthCommand);+ commandService.registerCommand(SetWorksheetColWidthMutation);++ const worksheet = get(ICurrentUniverService).getCurrentUniverSheetInstance().getWorkBook().getActiveSheet();+ const maxRow = worksheet.getMaxRows() - 1;+ const selectionManager = get(SelectionManagerService);+ selectionManager.setCurrentSelection({+ pluginName: NORMAL_SELECTION_PLUGIN_NAME,+ unitId: 'test',+ sheetId: 'sheet1',+ });+ selectionManager.add([+ {+ range: { startRow: 0, startColumn: 1, endColumn: 2, endRow: maxRow, rangeType: RANGE_TYPE.COLUMN },+ primary: {+ startRow: 0,+ startColumn: 1,+ endColumn: 1,+ endRow: 0,+ actualColumn: 1,+ actualRow: 1,+ isMerged: false,+ isMergedMainCell: false,+ },+ style: null,+ },+ ]);+ selectionManager.add([+ {+ range: { startRow: 0, startColumn: 5, endColumn: 5, endRow: maxRow, rangeType: RANGE_TYPE.COLUMN },+ primary: null,+ style: null,+ },+ ]);+ });++ afterEach(() => univer.dispose());++ describe('Delta col widths by dragging', () => {+ it('Should expand all col selections when anchor col is selected', async () => {+ expect(getColumnWidth(1)).toBe(73);++ await commandService.executeCommand<IDeltaColumnWidthCommandParams>(DeltaColumnWidthCommand.id, {+ deltaX: -23,+ anchorCol: 5,+ });+ expect(getColumnWidth(1)).toBe(50);+ expect(getColumnWidth(2)).toBe(50);+ expect(getColumnWidth(5)).toBe(50);++ await commandService.executeCommand(UndoCommand.id);+ expect(getColumnWidth(1)).toBe(73);+ expect(getColumnWidth(2)).toBe(73);+ expect(getColumnWidth(5)).toBe(73);++ await commandService.executeCommand(RedoCommand.id);+ expect(getColumnWidth(1)).toBe(50);+ expect(getColumnWidth(2)).toBe(50);+ expect(getColumnWidth(5)).toBe(50);+ });++ it('Should expand only the anchor col in other situations', () => {+ expect(getColumnWidth(1)).toBe(73);+ expect(getColumnWidth(7)).toBe(73);++ commandService.executeCommand<IDeltaColumnWidthCommandParams>(DeltaColumnWidthCommand.id, {+ deltaX: -23,+ anchorCol: 7,+ });++ expect(getColumnWidth(1)).toBe(73);+ expect(getColumnWidth(2)).toBe(73);+ expect(getColumnWidth(5)).toBe(73);+ expect(getColumnWidth(7)).toBe(50);+ });+ });++ it('Direct change col widths', async () => {+ expect(getColumnWidth(1)).toBe(73);++ await commandService.executeCommand<ISetColWidthCommandParams>(SetColWidthCommand.id, {+ value: 40,+ });+ expect(getColumnWidth(1)).toBe(40);+ expect(getColumnWidth(2)).toBe(40);+ expect(getColumnWidth(5)).toBe(40);++ await commandService.executeCommand(UndoCommand.id);+ expect(getColumnWidth(1)).toBe(73);+ expect(getColumnWidth(2)).toBe(73);+ expect(getColumnWidth(5)).toBe(73);++ await commandService.executeCommand(RedoCommand.id);+ expect(getColumnWidth(1)).toBe(40);+ expect(getColumnWidth(2)).toBe(40);+ expect(getColumnWidth(5)).toBe(40);+ });+});diff --git a/packages/base-sheets/src/commands/commands/__tests__/set-range-values-command.spec.ts b/packages/base-sheets/src/commands/commands/__tests__/set-range-values.command.spec.tssimilarity index 100%rename from packages/base-sheets/src/commands/commands/__tests__/set-range-values-command.spec.tsrename to packages/base-sheets/src/commands/commands/__tests__/set-range-values.command.spec.tsdiff --git a/packages/base-sheets/src/commands/commands/__tests__/set-row-height.command.spec.ts b/packages/base-sheets/src/commands/commands/__tests__/set-row-height.command.spec.tsnew file mode 100644index 0000000000..5126cfdd9f--- /dev/null+++ b/packages/base-sheets/src/commands/commands/__tests__/set-row-height.command.spec.ts@@ -0,0 +1,131 @@+/* eslint-disable no-magic-numbers */+import { ICommandService, ICurrentUniverService, RANGE_TYPE, RedoCommand, UndoCommand, Univer } from '@univerjs/core';+import { Injector } from '@wendellhu/redi';+import { afterEach, beforeEach, describe, expect, it } from 'vitest';++import { SetWorksheetRowHeightMutation } from '../../..';+import { NORMAL_SELECTION_PLUGIN_NAME, SelectionManagerService } from '../../../services/selection-manager.service';+import {+ DeltaRowHeightCommand,+ IDeltaRowHeightCommand,+ ISetRowHeightCommandParams,+ SetRowHeightCommand,+} from '../set-worksheet-row-height.command';+import { createCommandTestBed } from './create-command-test-bed';++// tests in this file is almost a transpose of packages/base-sheets/src/commands/commands/__tests__/set--width.command.spec.ts++describe('Test set row height commands', () => {+ let univer: Univer;+ let get: Injector['get'];+ let commandService: ICommandService;++ function getRowHeight(row: number): number {+ const worksheet = get(ICurrentUniverService).getCurrentUniverSheetInstance().getWorkBook().getActiveSheet();+ return worksheet.getRowHeight(row);+ }++ beforeEach(() => {+ const testBed = createCommandTestBed();+ univer = testBed.univer;+ get = testBed.get;++ commandService = get(ICommandService);+ commandService.registerCommand(DeltaRowHeightCommand);+ commandService.registerCommand(SetRowHeightCommand);+ commandService.registerCommand(SetWorksheetRowHeightMutation);++ const worksheet = get(ICurrentUniverService).getCurrentUniverSheetInstance().getWorkBook().getActiveSheet();+ const maxColumn = worksheet.getMaxColumns() - 1;+ const selectionManager = get(SelectionManagerService);+ selectionManager.setCurrentSelection({+ pluginName: NORMAL_SELECTION_PLUGIN_NAME,+ unitId: 'test',+ sheetId: 'sheet1',+ });+ selectionManager.add([+ {+ range: { startRow: 1, startColumn: 0, endRow: 2, endColumn: maxColumn, rangeType: RANGE_TYPE.ROW },+ primary: {+ startRow: 1,+ startColumn: 0,+ endColumn: 0,+ endRow: 1,+ actualColumn: 0,+ actualRow: 1,+ isMerged: false,+ isMergedMainCell: false,+ },+ style: null,+ },+ ]);+ selectionManager.add([+ {+ range: { startRow: 5, startColumn: 0, endColumn: maxColumn, endRow: 5, rangeType: RANGE_TYPE.ROW },+ primary: null,+ style: null,+ },+ ]);+ });++ afterEach(() => univer.dispose());++ describe('Delta row heights by dragging', () => {+ it('Should change all row selections when anchor row is selected', async () => {+ expect(getRowHeight(1)).toBe(19);++ await commandService.executeCommand<IDeltaRowHeightCommand>(DeltaRowHeightCommand.id, {+ deltaY: -5,+ anchorRow: 5,+ });+ expect(getRowHeight(1)).toBe(14);+ expect(getRowHeight(2)).toBe(14);+ expect(getRowHeight(5)).toBe(14);++ await commandService.executeCommand(UndoCommand.id);+ expect(getRowHeight(1)).toBe(19);+ expect(getRowHeight(2)).toBe(19);+ expect(getRowHeight(5)).toBe(19);++ await commandService.executeCommand(RedoCommand.id);+ expect(getRowHeight(1)).toBe(14);+ expect(getRowHeight(2)).toBe(14);+ expect(getRowHeight(5)).toBe(14);+ });++ it('Should expand only the anchor row in other situations', async () => {+ expect(getRowHeight(1)).toBe(19);+ expect(getRowHeight(7)).toBe(19);++ await commandService.executeCommand<IDeltaRowHeightCommand>(DeltaRowHeightCommand.id, {+ deltaY: -5,+ anchorRow: 7,+ });+ expect(getRowHeight(1)).toBe(19);+ expect(getRowHeight(2)).toBe(19);+ expect(getRowHeight(5)).toBe(19);+ expect(getRowHeight(7)).toBe(14);+ });+ });++ it('Direct change row heights', async () => {+ expect(getRowHeight(1)).toBe(19);++ await commandService.executeCommand<ISetRowHeightCommandParams>(SetRowHeightCommand.id, {+ value: 77,+ });+ expect(getRowHeight(1)).toBe(77);+ expect(getRowHeight(2)).toBe(77);+ expect(getRowHeight(5)).toBe(77);++ await commandService.executeCommand(UndoCommand.id);+ expect(getRowHeight(1)).toBe(19);+ expect(getRowHeight(2)).toBe(19);+ expect(getRowHeight(5)).toBe(19);++ await commandService.executeCommand(RedoCommand.id);+ expect(getRowHeight(1)).toBe(77);+ expect(getRowHeight(2)).toBe(77);+ expect(getRowHeight(5)).toBe(77);+ });+});diff --git a/packages/base-sheets/src/commands/commands/__tests__/set-selections.command.spec.ts b/packages/base-sheets/src/commands/commands/__tests__/set-selections.command.spec.tsindex 1e63d7d0ba..31b81b8471 100644--- a/packages/base-sheets/src/commands/commands/__tests__/set-selections.command.spec.ts+++ b/packages/base-sheets/src/commands/commands/__tests__/set-selections.command.spec.ts@@ -340,7 +340,6 @@ describe('Test commands used for change selections', () => {// shrink- console.log('debug', selectionManagerService.getLast());await commandService.executeCommand<IExpandSelectionCommandParams>(ExpandSelectionCommand.id, {direction: Direction.LEFT,jumpOver: true,diff --git a/packages/base-sheets/src/commands/commands/__tests__/set-style-command.spec.ts b/packages/base-sheets/src/commands/commands/__tests__/set-style.command.spec.tssimilarity index 100%rename from packages/base-sheets/src/commands/commands/__tests__/set-style-command.spec.tsrename to packages/base-sheets/src/commands/commands/__tests__/set-style.command.spec.tsdiff --git a/packages/base-sheets/src/commands/commands/move-rows-to.command.ts b/packages/base-sheets/src/commands/commands/move-rows-to.command.tsindex 8ca9123b31..049f2d150f 100644--- a/packages/base-sheets/src/commands/commands/move-rows-to.command.ts+++ b/packages/base-sheets/src/commands/commands/move-rows-to.command.ts@@ -77,8 +77,6 @@ export const MoveRowsToCommand: ICommand = {if (removeResult && result) {undoRedoService.pushUndoRedo({- // 如果有多个 mutation 构成一个封装项目,那么要封装在同一个 undo redo element 里面- // 通过勾子可以 hook 外部 controller 的代码来增加新的 actionURI: workbookId,undo() {return (diff --git a/packages/base-sheets/src/commands/commands/set-worksheet-col-width.command.ts b/packages/base-sheets/src/commands/commands/set-worksheet-col-width.command.tsindex 93f4817f94..bdd5f57deb 100644--- a/packages/base-sheets/src/commands/commands/set-worksheet-col-width.command.ts+++ b/packages/base-sheets/src/commands/commands/set-worksheet-col-width.command.ts@@ -5,6 +5,7 @@ import {ICurrentUniverService,IUndoRedoService,RANGE_TYPE,+ Rectangle,} from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';@@ -15,17 +16,17 @@ import {SetWorksheetColWidthMutationFactory,} from '../mutations/set-worksheet-col-width.mutation';-export interface IDeltaWorksheetColumnWidthCommandParams {+export interface IDeltaColumnWidthCommandParams {anchorCol: number;deltaX: number;}-export const DeltaWorksheetColumnWidthCommand: ICommand<IDeltaWorksheetColumnWidthCommandParams> = {+export const DeltaColumnWidthCommand: ICommand<IDeltaColumnWidthCommandParams> = {type: CommandType.COMMAND,id: 'sheet.command.delta-column-width',- handler: async (accessor: IAccessor, params: IDeltaWorksheetColumnWidthCommandParams) => {+ handler: async (accessor: IAccessor, params: IDeltaColumnWidthCommandParams) => {const selectionManagerService = accessor.get(SelectionManagerService);- const selections = selectionManagerService.getRangeDatas();+ const selections = selectionManagerService.getSelections();if (!selections?.length) {return false;}@@ -40,8 +41,9 @@ export const DeltaWorksheetColumnWidthCommand: ICommand<IDeltaWorksheetColumnWidconst anchorColWidth = worksheet.getColumnWidth(anchorCol);const destColumnWidth = anchorColWidth + deltaX;- const colSelections = selections.filter((r) => r.rangeType === RANGE_TYPE.COLUMN);- const rangeType = colSelections.some((r) => {+ const colSelections = selections.filter((s) => s.range.rangeType === RANGE_TYPE.COLUMN);+ const rangeType = colSelections.some((s) => {+ const r = s.range;if (r.startColumn <= anchorCol && anchorCol <= r.endColumn) {return true;}@@ -56,7 +58,7 @@ export const DeltaWorksheetColumnWidthCommand: ICommand<IDeltaWorksheetColumnWidredoMutationParams = {worksheetId,workbookId,- ranges: colSelections,+ ranges: colSelections.map((s) => Rectangle.clone(s.range)),colWidth: destColumnWidth,};} else {@@ -100,14 +102,14 @@ export const DeltaWorksheetColumnWidthCommand: ICommand<IDeltaWorksheetColumnWid},};-export interface SetWorksheetColWidthCommandParams {+export interface ISetColWidthCommandParams {value: number;}-export const SetWorksheetColWidthCommand: ICommand = {+export const SetColWidthCommand: ICommand = {type: CommandType.COMMAND,id: 'sheet.command.set-worksheet-col-width',- handler: async (accessor: IAccessor, params: SetWorksheetColWidthCommandParams) => {+ handler: async (accessor: IAccessor, params: ISetColWidthCommandParams) => {const selectionManagerService = accessor.get(SelectionManagerService);const commandService = accessor.get(ICommandService);const undoRedoService = accessor.get(IUndoRedoService);diff --git a/packages/base-sheets/src/commands/commands/set-worksheet-row-height.command.ts b/packages/base-sheets/src/commands/commands/set-worksheet-row-height.command.tsindex 3a0a1e4920..5944114d9f 100644--- a/packages/base-sheets/src/commands/commands/set-worksheet-row-height.command.ts+++ b/packages/base-sheets/src/commands/commands/set-worksheet-row-height.command.ts@@ -5,6 +5,7 @@ import {ICurrentUniverService,IUndoRedoService,RANGE_TYPE,+ Rectangle,} from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';@@ -15,17 +16,17 @@ import {SetWorksheetRowHeightMutationFactory,} from '../mutations/set-worksheet-row-height.mutation';-export interface IDeltaWorksheetRowHeightCommand {+export interface IDeltaRowHeightCommand {anchorRow: number;deltaY: number;}-export const DeltaWorksheetRowHeightCommand: ICommand = {+export const DeltaRowHeightCommand: ICommand = {type: CommandType.COMMAND,id: 'sheet.command.delta-row-height',- handler: async (accessor: IAccessor, params: IDeltaWorksheetRowHeightCommand) => {+ handler: async (accessor: IAccessor, params: IDeltaRowHeightCommand) => {const selectionManagerService = accessor.get(SelectionManagerService);- const selections = selectionManagerService.getRangeDatas();+ const selections = selectionManagerService.getSelections();if (!selections?.length) {return false;}@@ -40,8 +41,9 @@ export const DeltaWorksheetRowHeightCommand: ICommand = {const anchorRowHeight = worksheet.getRowHeight(anchorRow);const destRowHeight = anchorRowHeight + deltaY;- const rowSelections = selections.filter((r) => r.rangeType === RANGE_TYPE.ROW);- const rangeType = rowSelections.some((r) => {+ const rowSelections = selections.filter((s) => s.range.rangeType === RANGE_TYPE.ROW);+ const rangeType = rowSelections.some((s) => {+ const r = s.range;if (r.startRow <= anchorRow && anchorRow <= r.endRow) {return true;}@@ -56,7 +58,7 @@ export const DeltaWorksheetRowHeightCommand: ICommand = {redoMutationParams = {worksheetId,workbookId,- ranges: rowSelections,+ ranges: rowSelections.map((s) => Rectangle.clone(s.range)),rowHeight: destRowHeight,};} else {@@ -100,13 +102,13 @@ export const DeltaWorksheetRowHeightCommand: ICommand = {},};-export interface SetWorksheetRowHeightCommandParams {+export interface ISetRowHeightCommandParams {value: number;}-export const SetWorksheetRowHeightCommand: ICommand = {+export const SetRowHeightCommand: ICommand = {type: CommandType.COMMAND,- id: 'sheet.command.set-worksheet-row-height',- handler: async (accessor: IAccessor, params: SetWorksheetRowHeightCommandParams) => {+ id: 'sheet.command.set-row-height',+ handler: async (accessor: IAccessor, params: ISetRowHeightCommandParams) => {const selectionManagerService = accessor.get(SelectionManagerService);const commandService = accessor.get(ICommandService);const undoRedoService = accessor.get(IUndoRedoService);diff --git a/packages/base-sheets/src/index.ts b/packages/base-sheets/src/index.tsindex 8ca86b9aa2..0d2c35a525 100644--- a/packages/base-sheets/src/index.ts+++ b/packages/base-sheets/src/index.ts@@ -83,11 +83,11 @@ export {} from './commands/commands/set-style.command';export { SetTabColorCommand } from './commands/commands/set-tab-color.command';export { SetWorksheetActivateCommand } from './commands/commands/set-worksheet-activate.command';-export { SetWorksheetColWidthCommand } from './commands/commands/set-worksheet-col-width.command';+export { SetColWidthCommand as SetWorksheetColWidthCommand } from './commands/commands/set-worksheet-col-width.command';export { SetWorksheetHideCommand } from './commands/commands/set-worksheet-hide.command';export { SetWorksheetNameCommand } from './commands/commands/set-worksheet-name.command';export { SetWorksheetOrderCommand } from './commands/commands/set-worksheet-order.command';-export { SetWorksheetRowHeightCommand } from './commands/commands/set-worksheet-row-height.command';+export { SetRowHeightCommand as SetWorksheetRowHeightCommand } from './commands/commands/set-worksheet-row-height.command';export { SetWorksheetRowHideCommand } from './commands/commands/set-worksheet-row-hide.command';export { SetWorksheetRowShowCommand } from './commands/commands/set-worksheet-row-show.command';export { SetWorksheetShowCommand } from './commands/commands/set-worksheet-show.command';diff --git a/packages/base-sheets/src/services/selection-manager.service.ts b/packages/base-sheets/src/services/selection-manager.service.tsindex 98c746acb1..c213722b15 100644--- a/packages/base-sheets/src/services/selection-manager.service.ts+++ b/packages/base-sheets/src/services/selection-manager.service.ts@@ -94,12 +94,13 @@ export class SelectionManagerService implements IDisposable {return this._getSelectionDatas(param);}- getSelectionDatas(): Readonly<Nullable<ISelectionWithStyle[]>> {+ getSelections(): Readonly<Nullable<ISelectionWithStyle[]>> {return this._getSelectionDatas(this._currentSelection);}+ /** @deprecated use getSelectionsData instead */getRangeDatas(): Nullable<IRange[]> {- const selectionDataList = this.getSelectionDatas();+ const selectionDataList = this.getSelections();if (selectionDataList == null) {return;}diff --git a/packages/core/src/Sheets/Domain/Workbook.ts b/packages/core/src/Sheets/Domain/Workbook.tsindex 0180d6e968..d448beedad 100644--- a/packages/core/src/Sheets/Domain/Workbook.ts+++ b/packages/core/src/Sheets/Domain/Workbook.ts@@ -122,7 +122,6 @@ export class Workbook {return worksheet.getStatus() === BooleanNumber.TRUE;});if (!activeSheetId) {- console.warn('No active sheet, get first sheet');return this._worksheets.get(sheetOrder[0]) as Worksheet;}return this._worksheets.get(activeSheetId) as Worksheet;diff --git a/packages/ui-plugin-sheets/src/controller/sheet-ui.controller.ts b/packages/ui-plugin-sheets/src/controller/sheet-ui.controller.tsindex 1d11613665..720ddf62fb 100644--- a/packages/ui-plugin-sheets/src/controller/sheet-ui.controller.ts+++ b/packages/ui-plugin-sheets/src/controller/sheet-ui.controller.ts@@ -86,6 +86,7 @@ import {ExpandSelectionLeftShortcutItem,ExpandSelectionRightShortcutItem,ExpandSelectionUpShortcutItem,+ MoveBackSelectionShortcutItem,MoveSelectionDownShortcutItem,MoveSelectionEndDownShortcutItem,MoveSelectionEndLeftShortcutItem,@@ -214,6 +215,7 @@ export class SheetUIController extends Disposable {MoveSelectionLeftShortcutItem,MoveSelectionRightShortcutItem,MoveSelectionTabShortcutItem,+ MoveBackSelectionShortcutItem,MoveSelectionEndDownShortcutItem,MoveSelectionEndUpShortcutItem,MoveSelectionEndLeftShortcutItem,diff --git a/packages/ui-plugin-sheets/src/controller/shortcuts/selection.shortcut.ts b/packages/ui-plugin-sheets/src/controller/shortcuts/selection.shortcut.tsindex 22e39c5ea0..a99081e0a1 100644--- a/packages/ui-plugin-sheets/src/controller/shortcuts/selection.shortcut.ts+++ b/packages/ui-plugin-sheets/src/controller/shortcuts/selection.shortcut.ts@@ -56,6 +56,15 @@ export const MoveSelectionTabShortcutItem: IShortcutItem<IMoveSelectionCommandPa},};+export const MoveBackSelectionShortcutItem: IShortcutItem<IMoveSelectionCommandParams> = {+ id: MoveSelectionCommand.id,+ binding: KeyCode.TAB | MetaKeys.SHIFT,+ preconditions: (contextService) => contextService.getContextValue(FOCUSING_SHEET),+ staticParameters: {+ direction: Direction.LEFT,+ },+};+// move selection to continuous endexport const MoveSelectionEndDownShortcutItem: IShortcutItem<IMoveSelectionCommandParams> = {diff --git a/packages/ui-plugin-sheets/src/controller/shortcuts/value.shortcut.ts b/packages/ui-plugin-sheets/src/controller/shortcuts/value.shortcut.tsindex e908342e10..7c7b014524 100644--- a/packages/ui-plugin-sheets/src/controller/shortcuts/value.shortcut.ts+++ b/packages/ui-plugin-sheets/src/controller/shortcuts/value.shortcut.ts@@ -4,6 +4,7 @@ import { FOCUSING_SHEET } from '@univerjs/core';export const ClearSelectionValueShortcutItem: IShortcutItem = {id: ClearSelectionContentCommand.id,- preconditions: (contextService) => contextService.getContextValue(FOCUSING_SHEET),+ preconditions: (contextService) =>+ contextService.getContextValue(FOCUSING_SHEET) && document.activeElement?.tagName === 'canvas',binding: KeyCode.BACKSPACE,};