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): paste without numfmt (#838)

Gpound.liu8357afb240f9
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 c29ec3ea71..322de32e05 100644
--- a/packages/sheets-numfmt/src/controllers/numfmt.copy-paste.controller.ts
+++ b/packages/sheets-numfmt/src/controllers/numfmt.copy-paste.controller.ts
@@ -34,7 +34,7 @@ import {
SetNumfmtMutation,
transformCellsToRange,
} from '@univerjs/sheets';
-import { COPY_TYPE, getRepeatRange, ISheetClipboardService } from '@univerjs/sheets-ui';
+import { COPY_TYPE, getRepeatRange, ISheetClipboardService, PREDEFINED_HOOK_NAME } from '@univerjs/sheets-ui';
import { Inject, Injector } from '@wendellhu/redi';
@OnLifecycle(LifecycleStages.Rendered, NumfmtCopyPasteController)
@@ -62,7 +62,8 @@ export class NumfmtCopyPasteController extends Disposable {
this._sheetClipboardService.addClipboardHook({
hookName: 'numfmt',
onBeforeCopy: (unitId, subUnitId, range) => this._collectNumfmt(unitId, subUnitId, range),
- onPasteCells: (pastedRange, _m, _p, _copyInfo) => this._generateNumfmtMutations(pastedRange, _copyInfo),
+ onPasteCells: (pastedRange, _m, _p, _copyInfo) =>
+ this._generateNumfmtMutations(pastedRange, { ..._copyInfo, pasteType: _p }),
})
);
}
@@ -106,6 +107,7 @@ export class NumfmtCopyPasteController extends Disposable {
copyInfo: {
copyType: COPY_TYPE;
copyRange?: IRange;
+ pasteType: string;
}
) {
const workbook = this._univerInstanceService.getCurrentUniverSheetInstance();
@@ -123,6 +125,13 @@ export class NumfmtCopyPasteController extends Disposable {
return { redos: [], undos: [] };
}
+ if (
+ [PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH, PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE].includes(
+ copyInfo.pasteType
+ )
+ ) {
+ return { redos: [], undos: [] };
+ }
const repeatRange = getRepeatRange(copyInfo.copyRange, pastedRange, true);
const cells: ISetCellsNumfmt = [];
const removeRedos: IRemoveNumfmtMutationParams = { unitId, subUnitId, ranges: [] };
diff --git a/packages/sheets-ui/src/index.ts b/packages/sheets-ui/src/index.ts
index 1673256dec..83d24d1f41 100644
--- a/packages/sheets-ui/src/index.ts
+++ b/packages/sheets-ui/src/index.ts
@@ -41,10 +41,12 @@ export { getAutoFillRepeatRange } from './services/auto-fill/tools';
export type { IAutoFillHook, ICopyDataPiece } from './services/auto-fill/type';
export { APPLY_TYPE, DATA_TYPE, type IAutoFillRule } from './services/auto-fill/type';
export { type ICopyDataInTypeIndexInfo } from './services/auto-fill/type';
-export { ISheetClipboardService } from './services/clipboard/clipboard.service';
-export { SheetClipboardService } from './services/clipboard/clipboard.service';
-export { type ISheetClipboardHook } from './services/clipboard/type';
-export { type ICellDataWithSpanInfo } from './services/clipboard/type';
+export {
+ ISheetClipboardService,
+ PREDEFINED_HOOK_NAME,
+ SheetClipboardService,
+} from './services/clipboard/clipboard.service';
+export type { ICellDataWithSpanInfo, ISheetClipboardHook } from './services/clipboard/type';
export { COPY_TYPE } from './services/clipboard/type';
export { getRepeatRange } from './services/clipboard/utils';
export { CellEditorManagerService, ICellEditorManagerService } from './services/editor/cell-editor-manager.service';
diff --git a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx
index f51cff755c..b288e47b25 100644
--- a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx
+++ b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx
@@ -99,7 +99,10 @@ export function SheetBarTabs() {
commandService.executeCommand(SetWorksheetOrderCommand.id, { order });
},
onChangeTab: (event: Event, subUnitId: string) => {
- commandService.executeCommand(SetWorksheetActivateCommand.id, { subUnitId });
+ commandService.executeCommand(SetWorksheetActivateCommand.id, {
+ subUnitId,
+ unitId: workbook.getUnitId(),
+ });
},
onScroll: (state: IScrollState) => {
sheetBarService.setScroll(state);