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.

feat: trigger auto height after set range value (#334)

Ran Luo9a505ec3ba9d
diff --git a/packages/base-sheets/src/Controller/auto-height.controller.ts b/packages/base-sheets/src/Controller/auto-height.controller.ts
index 4a1e92799c..85945ba3b1 100644
--- a/packages/base-sheets/src/Controller/auto-height.controller.ts
+++ b/packages/base-sheets/src/Controller/auto-height.controller.ts
@@ -1,9 +1,11 @@
import { IRange, IUniverInstanceService, LifecycleStages, OnLifecycle, SheetInterceptorService } from '@univerjs/core';
import { Inject, Injector } from '@wendellhu/redi';
+import { SetRangeValuesCommand } from '../commands/commands/set-range-values.command';
import { ISetStyleParams, SetStyleCommand } from '../commands/commands/set-style.command';
import { DeltaColumnWidthCommand, SetColWidthCommand } from '../commands/commands/set-worksheet-col-width.command';
import { SetWorksheetRowIsAutoHeightCommand } from '../commands/commands/set-worksheet-row-height.command';
+import { ISetRangeValuesMutationParams } from '../commands/mutations/set-range-values.mutation';
import { ISetWorksheetColWidthMutationParams } from '../commands/mutations/set-worksheet-col-width.mutation';
import {
ISetWorksheetRowAutoHeightMutationParams,
@@ -70,6 +72,19 @@ export class AutoHeightController {
private _initialize() {
const { _sheetInterceptorService: sheetInterceptorService, _selectionManagerService: selectionManagerService } =
this;
+ // for intercept'SetRangeValuesCommand' command.
+ sheetInterceptorService.interceptCommand({
+ getMutations: (command: { id: string; params: ISetRangeValuesMutationParams }) => {
+ if (command.id !== SetRangeValuesCommand.id) {
+ return {
+ redos: [],
+ undos: [],
+ };
+ }
+
+ return this._getUndoRedoParamsOfAutoHeight(command.params.range);
+ },
+ });
// for intercept 'sheet.command.set-row-is-auto-height' command.
sheetInterceptorService.interceptCommand({
getMutations: (command: { id: string; params: ISetWorksheetRowIsAutoHeightMutationParams }) => {
diff --git a/packages/base-sheets/src/commands/commands/set-range-values.command.ts b/packages/base-sheets/src/commands/commands/set-range-values.command.ts
index 244dc28b5a..9ad946b059 100644
--- a/packages/base-sheets/src/commands/commands/set-range-values.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-range-values.command.ts
@@ -9,6 +9,8 @@ import {
IUniverInstanceService,
ObjectMatrix,
ObjectMatrixPrimitiveType,
+ sequenceExecute,
+ SheetInterceptorService,
Tools,
} from '@univerjs/core';
import { IAccessor } from '@wendellhu/redi';
@@ -95,19 +97,31 @@ export const SetRangeValuesCommand: ICommand = {
setRangeValuesMutationParams
);
- const result = commandService.syncExecuteCommand(SetRangeValuesMutation.id, setRangeValuesMutationParams);
- if (result) {
+ const setValueMutationResult = commandService.syncExecuteCommand(
+ SetRangeValuesMutation.id,
+ setRangeValuesMutationParams
+ );
+
+ const { undos, redos } = accessor.get(SheetInterceptorService).onCommandExecute({
+ id: SetRangeValuesCommand.id,
+ params: setRangeValuesMutationParams,
+ });
+
+ const result = sequenceExecute([...redos], commandService);
+
+ if (setValueMutationResult && result.result) {
undoRedoService.pushUndoRedo({
URI: workbookId,
- undo() {
- return commandService.syncExecuteCommand(
- SetRangeValuesMutation.id,
- undoSetRangeValuesMutationParams
- );
- },
- redo() {
- return commandService.syncExecuteCommand(SetRangeValuesMutation.id, setRangeValuesMutationParams);
- },
+ undo: async () =>
+ sequenceExecute(
+ [{ id: SetRangeValuesMutation.id, params: undoSetRangeValuesMutationParams }, ...undos],
+ commandService
+ ).result,
+ redo: async () =>
+ sequenceExecute(
+ [{ id: SetRangeValuesMutation.id, params: setRangeValuesMutationParams }, ...redos],
+ commandService
+ ).result,
});
return true;
diff --git a/packages/ui-plugin-sheets/src/controller/editor-bridge.controller.ts b/packages/ui-plugin-sheets/src/controller/editor-bridge.controller.ts
index d44a8112ce..6d64be7c33 100644
--- a/packages/ui-plugin-sheets/src/controller/editor-bridge.controller.ts
+++ b/packages/ui-plugin-sheets/src/controller/editor-bridge.controller.ts
@@ -35,8 +35,7 @@ export class EditorBridgeController extends Disposable {
@IRenderManagerService private readonly _renderManagerService: IRenderManagerService,
@IEditorBridgeService private readonly _editorBridgeService: IEditorBridgeService,
@Inject(SelectionManagerService) private readonly _selectionManagerService: SelectionManagerService,
- @ISelectionRenderService
- private readonly _selectionRenderService: ISelectionRenderService
+ @ISelectionRenderService private readonly _selectionRenderService: ISelectionRenderService
) {
super();
diff --git a/packages/ui-plugin-sheets/src/controller/format-painter/format-painter.controller.ts b/packages/ui-plugin-sheets/src/controller/format-painter/format-painter.controller.ts
index bca1648fe4..3e202b534a 100644
--- a/packages/ui-plugin-sheets/src/controller/format-painter/format-painter.controller.ts
+++ b/packages/ui-plugin-sheets/src/controller/format-painter/format-painter.controller.ts
@@ -76,16 +76,19 @@ export class FormatPainterController extends Disposable {
const workbookId = this._currentService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = this._currentService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();
if (!stylesMatrix) return;
+
const styleRowsNum = stylesMatrix.getLength();
const styleColsNum = stylesMatrix.getSizeOf();
const styleValues: ICellData[][] = Array.from({ length: range.endRow - range.startRow + 1 }, () =>
Array.from({ length: range.endColumn - range.startColumn + 1 }, () => ({}))
);
+
styleValues.forEach((row, rowIndex) => {
row.forEach((col, colIndex) => {
const mappedRowIndex = rowIndex % styleRowsNum;
const mappedColIndex = colIndex % styleColsNum;
const style = stylesMatrix.getValue(mappedRowIndex, mappedColIndex);
+
if (style) {
styleValues[rowIndex][colIndex].s = style;
}
@@ -98,6 +101,7 @@ export class FormatPainterController extends Disposable {
range,
value: styleValues,
};
+
this._commandService.executeCommand(SetRangeValuesCommand.id, setRangeValuesCommandParams);
// if the format painter is once, turn it off