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: fix snapshot after cut & paste (#4405)

ybzky52990cc049f5
diff --git a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts b/packages/sheets-ui/src/services/clipboard/clipboard.service.ts
index f41eb4b173..31425f007b 100644
--- a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts
+++ b/packages/sheets-ui/src/services/clipboard/clipboard.service.ts
@@ -23,6 +23,7 @@ import type {
import type { ISetSelectionsOperationParams } from '@univerjs/sheets';
import type { IDiscreteRange } from '../../controllers/utils/range-tools';
import type {
+ ICellDataWithSpanInfo,
IClipboardPropertyItem,
IPasteTarget,
ISheetClipboardHook,
@@ -305,9 +306,11 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
const { startColumn, startRow, endColumn, endRow } = range;
const matrix = worksheet.getMatrixWithMergedCells(startRow, startColumn, endRow, endColumn, CellModeEnum.Both);
- const matrixFragment = new ObjectMatrix<ICellDataWithSpanAndDisplay>();
+ const matrixFragment = new ObjectMatrix<ICellDataWithSpanInfo>();
let rowIndex = startRow;
+ const plainMatrix = new ObjectMatrix<ICellDataWithSpanAndDisplay>();
+
const discreteRange: IDiscreteRange = { rows: [], cols: [] };
for (let r = startRow; r <= endRow; r++) {
if (filteredRows.has(r)) {
@@ -317,11 +320,19 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
for (let c = startColumn; c <= endColumn; c++) {
const cellData = matrix.getValue(r, c);
if (cellData) {
+ const newCellData = Tools.deepClone(cellData);
+ plainMatrix.setValue(rowIndex - startRow, c - startColumn, {
+ ...getEmptyCell(),
+ ...newCellData,
+ });
+
+ delete newCellData.displayV;
matrixFragment.setValue(rowIndex - startRow, c - startColumn, {
...getEmptyCell(),
- ...Tools.deepClone(cellData),
+ ...newCellData,
});
} else {
+ plainMatrix.setValue(rowIndex - startRow, c - startColumn, getEmptyCell());
matrixFragment.setValue(rowIndex - startRow, c - startColumn, getEmptyCell());
matrix.setValue(r, c, getEmptyCell());
}
@@ -335,7 +346,7 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
// convert matrix to html
let html = this._usmToHtml.convert(matrix, discreteRange, hooks);
- const plain = getMatrixPlainText(matrixFragment);
+ const plain = getMatrixPlainText(plainMatrix);
const copyId = genId();
html = html.replace(/(<[a-z]+)/, (_p0, p1) => `${p1} data-copy-id="${copyId}"`);