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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(sheet): add from & to range in moverange & clone the cellvalue (#3044)
VicKunbd913173c6c6
diff --git a/packages/core/src/shared/tools.ts b/packages/core/src/shared/tools.tsindex 183ffc8f8d..b3b31b11bc 100644--- a/packages/core/src/shared/tools.ts+++ b/packages/core/src/shared/tools.ts@@ -258,7 +258,7 @@ export class Tools {return diffArrays(oneValue, towValue);}if (Tools.isObject(oneValue)) {- return diffObject(oneValue as Object, towValue);+ return diffObject(oneValue as object, towValue);}if (Tools.isDate(oneValue)) {return (oneValue as Date).getTime() === towValue.getTime();diff --git a/packages/sheets-ui/src/controllers/clipboard/utils.ts b/packages/sheets-ui/src/controllers/clipboard/utils.tsindex f126b4102f..8d6dd10910 100644--- a/packages/sheets-ui/src/controllers/clipboard/utils.ts+++ b/packages/sheets-ui/src/controllers/clipboard/utils.ts@@ -140,6 +140,8 @@ export function getMoveRangeMutations(});const doMoveRangeMutation: IMoveRangeMutationParams = {+ fromRange,+ toRange,from: {value: newFromCellValue.getMatrix(),subUnitId: fromSubUnitId,@@ -151,6 +153,8 @@ export function getMoveRangeMutations(unitId,};const undoMoveRangeMutation: IMoveRangeMutationParams = {+ fromRange: toRange,+ toRange: fromRange,from: {value: fromCellValue.getMatrix(),subUnitId: fromSubUnitId,diff --git a/packages/sheets-ui/src/controllers/render-controllers/sheet.render-controller.ts b/packages/sheets-ui/src/controllers/render-controllers/sheet.render-controller.tsindex ddab5fb57a..e9d340cb23 100644--- a/packages/sheets-ui/src/controllers/render-controllers/sheet.render-controller.ts+++ b/packages/sheets-ui/src/controllers/render-controllers/sheet.render-controller.ts@@ -339,8 +339,9 @@ export class SheetRenderController extends RxDisposable implements IRenderModule}if (command.id === MoveRangeMutation.id && cmdParams.from && cmdParams.to) {- const fromRange = this._cellValueToRange(cmdParams.from.value);- const toRange = this._cellValueToRange(cmdParams.to.value);+ // keep the get _cellValueToRange code to ensure the code can effect as before+ const fromRange = cmdParams.fromRange || this._cellValueToRange(cmdParams.from.value);+ const toRange = cmdParams.toRange || this._cellValueToRange(cmdParams.to.value);const dirtyBounds = this._rangeToBounds([fromRange, toRange]);this._markViewportDirty(viewports, dirtyBounds);(spreadsheet as unknown as Spreadsheet).setDirtyArea(dirtyBounds);diff --git a/packages/sheets/src/commands/commands/move-range.command.ts b/packages/sheets/src/commands/commands/move-range.command.tsindex 0a501ffa3d..5f466eed21 100644--- a/packages/sheets/src/commands/commands/move-range.command.ts+++ b/packages/sheets/src/commands/commands/move-range.command.ts@@ -27,6 +27,7 @@ import {Range,Rectangle,sequenceExecute,+ Tools,} from '@univerjs/core';import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service';@@ -153,25 +154,26 @@ export function getMoveRangeUndoRedoMutations(const newFromCellValue = new ObjectMatrix<Nullable<ICellData>>();Range.foreach(fromRange, (row, col) => {- fromCellValue.setValue(row, col, fromCellMatrix.getValue(row, col));+ fromCellValue.setValue(row, col, Tools.deepClone(fromCellMatrix.getValue(row, col)));newFromCellValue.setValue(row, col, null);});const toCellValue = new ObjectMatrix<Nullable<ICellData>>();+ const newToCellValue = new ObjectMatrix<Nullable<ICellData>>();Range.foreach(toRange, (row, col) => {- toCellValue.setValue(row, col, toCellMatrix.getValue(row, col));+ toCellValue.setValue(row, col, Tools.deepClone(toCellMatrix.getValue(row, col)));});- const newToCellValue = new ObjectMatrix<Nullable<ICellData>>();-Range.foreach(fromRange, (row, col) => {const cellRange = cellToRange(row, col);const relativeRange = Rectangle.getRelativeRange(cellRange, fromRange);const range = Rectangle.getPositionRange(relativeRange, toRange);- newToCellValue.setValue(range.startRow, range.startColumn, fromCellMatrix.getValue(row, col));+ newToCellValue.setValue(range.startRow, range.startColumn, Tools.deepClone(fromCellMatrix.getValue(row, col)));});const doMoveRangeMutation: IMoveRangeMutationParams = {+ fromRange: from.range,+ toRange: to.range,from: {value: newFromCellValue.getMatrix(),subUnitId: fromSubUnitId,@@ -183,6 +185,8 @@ export function getMoveRangeUndoRedoMutations(unitId,};const undoMoveRangeMutation: IMoveRangeMutationParams = {+ fromRange: to.range,+ toRange: from.range,from: {value: fromCellValue.getMatrix(),subUnitId: fromSubUnitId,diff --git a/packages/sheets/src/commands/mutations/move-range.mutation.ts b/packages/sheets/src/commands/mutations/move-range.mutation.tsindex 096f78a2cb..9f88f1623e 100644--- a/packages/sheets/src/commands/mutations/move-range.mutation.ts+++ b/packages/sheets/src/commands/mutations/move-range.mutation.ts@@ -14,11 +14,13 @@* limitations under the License.*/-import type { ICellData, IMutation, IObjectMatrixPrimitiveType, Nullable, Workbook } from '@univerjs/core';+import type { ICellData, IMutation, IObjectMatrixPrimitiveType, IRange, Nullable, Workbook } from '@univerjs/core';import { CommandType, IUniverInstanceService, ObjectMatrix, UniverInstanceType } from '@univerjs/core';export interface IMoveRangeMutationParams {unitId: string;+ fromRange: IRange;+ toRange: IRange;from: {subUnitId: string;value: IObjectMatrixPrimitiveType<Nullable<ICellData>>;diff --git a/packages/sheets/src/services/ref-range/util.ts b/packages/sheets/src/services/ref-range/util.tsindex 31afe52bc4..5d4b0555b1 100644--- a/packages/sheets/src/services/ref-range/util.ts+++ b/packages/sheets/src/services/ref-range/util.ts@@ -1041,6 +1041,7 @@ export const handleCommonDefaultRangeChangeWithEffectRefCommands = (range: IRang* @param mutation* @returns the adjusted range*/+// eslint-disable-next-line max-lines-per-functionexport function adjustRangeOnMutation(range: Readonly<IRange>, mutation: IMutationInfo<MutationsAffectRange>): Nullable<IRange> {// we map mutation params to correspondingconst { id, params } = mutation;@@ -1098,11 +1099,20 @@ export function adjustRangeOnMutation(range: Readonly<IRange>, mutation: IMutatibaseRangeOperator.type = OperatorType.HorizontalMove;break;case MoveRangeMutation.id:- baseRangeOperator = handleBaseMoveRange(- new ObjectMatrix((params as IMoveRangeMutationParams).from).getRange(),- new ObjectMatrix((params as IMoveRangeMutationParams).to).getRange(),- range- );+ // baseRangeOperator = handleBaseMoveRange(+ // new ObjectMatrix((params as IMoveRangeMutationParams).from).getRange(),+ // new ObjectMatrix((params as IMoveRangeMutationParams).to).getRange(),+ // range+ // );+ {+ const fromRange = (params as IMoveRangeMutationParams).fromRange;+ const toRange = (params as IMoveRangeMutationParams).toRange;+ baseRangeOperator = handleBaseMoveRange(+ fromRange,+ toRange,+ range+ );+ }break;default:break;