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.

chore: add params to resolve confirm dialog show (#4246)

ybzkyd6415f9c60f6
diff --git a/packages/sheets-ui/src/commands/commands/add-worksheet-merge.command.ts b/packages/sheets-ui/src/commands/commands/add-worksheet-merge.command.ts
index aba7ed94f6..00d6f82d39 100644
--- a/packages/sheets-ui/src/commands/commands/add-worksheet-merge.command.ts
+++ b/packages/sheets-ui/src/commands/commands/add-worksheet-merge.command.ts
@@ -48,6 +48,7 @@ export interface IAddMergeCommandParams {
selections: IRange[];
unitId: string;
subUnitId: string;
+ defaultMerge?: boolean;
}
export const AddWorksheetMergeCommand: ICommand = {
@@ -72,7 +73,7 @@ export const AddWorksheetMergeCommand: ICommand = {
// First we should check if there are values in the going-to-be-merged cells.
const willClearSomeCell = checkCellContentInRanges(worksheet, ranges);
- if (willClearSomeCell) {
+ if (willClearSomeCell && !params.defaultMerge) {
const result = await confirmService.confirm({
id: 'merge.confirm.add-worksheet-merge',
title: {
diff --git a/packages/sheets/src/commands/commands/add-worksheet-merge.command.ts b/packages/sheets/src/commands/commands/add-worksheet-merge.command.ts
index 15387ee8f2..f74c51d9a7 100644
--- a/packages/sheets/src/commands/commands/add-worksheet-merge.command.ts
+++ b/packages/sheets/src/commands/commands/add-worksheet-merge.command.ts
@@ -265,7 +265,7 @@ export const AddWorksheetMergeHorizontalCommand: ICommand = {
},
};
-export async function addMergeCellsUtil(injector: Injector, unitId: string, subUnitId: string, ranges: IRange[]) {
+export async function addMergeCellsUtil(injector: Injector, unitId: string, subUnitId: string, ranges: IRange[], defaultMerge: boolean) {
const univerInstanceService = injector.get(IUniverInstanceService);
const target = getSheetCommandTarget(univerInstanceService, { unitId, subUnitId });
if (!target) return;
@@ -284,5 +284,6 @@ export async function addMergeCellsUtil(injector: Injector, unitId: string, subU
unitId,
subUnitId,
selections: ranges,
+ defaultMerge,
});
}
diff --git a/packages/sheets/src/facade/f-range.ts b/packages/sheets/src/facade/f-range.ts
index 9a944b062a..79ddc4d12d 100644
--- a/packages/sheets/src/facade/f-range.ts
+++ b/packages/sheets/src/facade/f-range.ts
@@ -528,41 +528,50 @@ export class FRange extends FBase {
/**
* Merge cells in a range into one merged cell
+ *
+ * @param [defaultMerge] - If true, only the value in the upper left cell is retained.
+ *
* @returns This range, for chaining
*/
- async merge(): Promise<FRange> {
+ async merge(defaultMerge: boolean = true): Promise<FRange> {
const unitId = this._workbook.getUnitId();
const subUnitId = this._worksheet.getSheetId();
- await addMergeCellsUtil(this._injector, unitId, subUnitId, [this._range]);
+ await addMergeCellsUtil(this._injector, unitId, subUnitId, [this._range], defaultMerge);
return this;
}
/**
* Merges cells in a range horizontally.
+ *
+ * @param [defaultMerge] - If true, only the value in the upper left cell is retained.
+ *
* @returns This range, for chaining
*/
- async mergeAcross(): Promise<FRange> {
+ async mergeAcross(defaultMerge: boolean = true): Promise<FRange> {
const ranges = getAddMergeMutationRangeByType([this._range], Dimension.ROWS);
const unitId = this._workbook.getUnitId();
const subUnitId = this._worksheet.getSheetId();
- await addMergeCellsUtil(this._injector, unitId, subUnitId, ranges);
+ await addMergeCellsUtil(this._injector, unitId, subUnitId, ranges, defaultMerge);
return this;
}
/**
* Merges cells in a range vertically.
+ *
+ * @param [defaultMerge] - If true, only the value in the upper left cell is retained.
+ *
* @returns This range, for chaining
*/
- async mergeVertically(): Promise<FRange> {
+ async mergeVertically(defaultMerge: boolean = true): Promise<FRange> {
const ranges = getAddMergeMutationRangeByType([this._range], Dimension.COLUMNS);
const unitId = this._workbook.getUnitId();
const subUnitId = this._worksheet.getSheetId();
- await addMergeCellsUtil(this._injector, unitId, subUnitId, ranges);
+ await addMergeCellsUtil(this._injector, unitId, subUnitId, ranges, defaultMerge);
return this;
}