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(numfmt): clear format should not merge cells without numfmt (#714)

Gpound.liuac3c4a90b9c5
diff --git a/packages/sheets-numfmt/src/controllers/numfmt.controller.ts b/packages/sheets-numfmt/src/controllers/numfmt.controller.ts
index df17b8d496..c1ea25c23a 100644
--- a/packages/sheets-numfmt/src/controllers/numfmt.controller.ts
+++ b/packages/sheets-numfmt/src/controllers/numfmt.controller.ts
@@ -224,9 +224,17 @@ export class NumfmtController extends Disposable implements INumfmtController {
worksheetId,
ranges: [],
};
+ const numfmtModel = self._numfmtService.getModel(workbookId, worksheetId);
selections.forEach((range) => {
Range.foreach(range, (row, col) => {
- redos.ranges.push({ startColumn: col, endColumn: col, startRow: row, endRow: row });
+ if (numfmtModel?.getValue(row, col)) {
+ redos.ranges.push({
+ startColumn: col,
+ endColumn: col,
+ startRow: row,
+ endRow: row,
+ });
+ }
});
});
redos.ranges = rangeMerge(redos.ranges);
diff --git a/packages/sheets-numfmt/src/controllers/numfmt.copy-paste.controller.ts b/packages/sheets-numfmt/src/controllers/numfmt.copy-paste.controller.ts
index 31b8d6072e..94d5bbc939 100644
--- a/packages/sheets-numfmt/src/controllers/numfmt.copy-paste.controller.ts
+++ b/packages/sheets-numfmt/src/controllers/numfmt.copy-paste.controller.ts
@@ -126,9 +126,13 @@ export class NumfmtCopyPasteController extends Disposable {
const repeatRange = getRepeatRange(copyInfo.copyRange, pastedRange, true);
const cells: ISetCellsNumfmt = [];
const removeRedos: IRemoveNumfmtMutationParams = { workbookId, worksheetId, ranges: [] };
-
+ const numfmtModel = this._numfmtService.getModel(workbookId, worksheetId);
// Clears the destination area data format
- removeRedos.ranges.push(pastedRange);
+ Range.foreach(pastedRange, (row, col) => {
+ if (this._numfmtService.getValue(workbookId, worksheetId, row, col, numfmtModel!)) {
+ removeRedos.ranges.push({ startRow: row, startColumn: col, endRow: row, endColumn: col });
+ }
+ });
// Set up according to the data collected. This will overlap with the cleanup, but that's okay
repeatRange.forEach((item) => {
diff --git a/packages/sheets-numfmt/src/controllers/numfmt.ref-range.controller.ts b/packages/sheets-numfmt/src/controllers/numfmt.ref-range.controller.ts
index 578b051a50..13178fb39b 100644
--- a/packages/sheets-numfmt/src/controllers/numfmt.ref-range.controller.ts
+++ b/packages/sheets-numfmt/src/controllers/numfmt.ref-range.controller.ts
@@ -27,7 +27,6 @@ import {
} from '@univerjs/core';
import type {
EffectRefRangeParams,
- FormatType,
IRemoveNumfmtMutationParams,
ISetCellsNumfmt,
ISetNumfmtMutationParams,
@@ -46,7 +45,6 @@ import {
handleIRemoveRow,
handleMoveRange,
INumfmtService,
- rangeMerge,
RefRangeService,
RemoveNumfmtMutation,
runRefRangeMutations,
@@ -77,81 +75,6 @@ export class NumfmtRefRangeController extends Disposable {
this._mergeRefMutations();
}
- private _refToReal(values: ISetNumfmtMutationParams['values'], refMap: ISetNumfmtMutationParams['refMap']) {
- const patternMap: {
- [pattern: string]: {
- pattern: string;
- ranges: IRange[];
- type: FormatType;
- };
- } = {};
-
- Object.keys(values).forEach((id) => {
- const v = refMap[id];
- if (!v) {
- return;
- }
- const ranges = values[id].ranges;
- const pattern = v.pattern;
- const type = v.type;
- patternMap[pattern] = { ranges, pattern, type };
- });
- return patternMap;
- }
-
- private _mergeNumfmtSetMutation(list: ISetNumfmtMutationParams[]) {
- if (!list.length) {
- return [];
- }
- const firstOne = list[0];
- const patternMap: {
- [pattern: string]: {
- pattern: string;
- ranges: IRange[];
- type: FormatType;
- };
- } = {};
- const refMap: ISetNumfmtMutationParams['refMap'] = {};
- const values: ISetNumfmtMutationParams['values'] = {};
- list.forEach((item) => {
- const { refMap, values } = item;
- const value = this._refToReal(values, refMap);
- Object.keys(value).forEach((key) => {
- if (patternMap[key]) {
- patternMap[key].ranges.push(...value[key].ranges);
- } else {
- patternMap[key] = value[key];
- }
- });
- });
- Object.keys(patternMap).forEach((key, index) => {
- const id = `${index + 1}`;
- const item = patternMap[key];
- refMap[id] = { pattern: item.pattern, type: item.type };
- values[id] = { ranges: rangeMerge(item.ranges) };
- });
- return {
- ...firstOne,
- refMap,
- values,
- };
- }
-
- private _mergeNumfmtRemoveMutation(list: IRemoveNumfmtMutationParams[]) {
- if (!list.length) {
- return [];
- }
- const ranges: IRange[] = [];
- list.forEach((item) => {
- ranges.push(...item.ranges);
- });
- const firstOne = list[0];
- return {
- ...firstOne,
- ranges: rangeMerge(ranges),
- };
- }
-
private _mergeRefMutations() {
this._refRangeService.interceptor.intercept(this._refRangeService.interceptor.getInterceptPoints().MERGE_REDO, {
handler: (list, _c, next) => {