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: cell style in collaboration (#3748)

lumixe138b95ac6c8
diff --git a/e2e/perf/scroll.spec.ts b/e2e/perf/scroll.spec.ts
index ab638fc888..8ac962414b 100644
--- a/e2e/perf/scroll.spec.ts
+++ b/e2e/perf/scroll.spec.ts
@@ -52,7 +52,7 @@ async function measureFPS(page: Page, testDuration = 5, deltaX: number, deltaY:
const fpsCounterPromise = await page.evaluate(({ testDuration, deltaX, deltaY }: IMeasureFPSParam) => {
let intervalID;
// dispatch wheel event
- const dispathWheelEvent = () => {
+ const dispatchWheelEvent = () => {
const canvasElements = document.querySelectorAll('canvas.univer-render-canvas') as unknown as HTMLElement[];
const filteredCanvasElements = Array.from(canvasElements).filter((canvas) => canvas.offsetHeight > 500);
@@ -95,7 +95,7 @@ async function measureFPS(page: Page, testDuration = 5, deltaX: number, deltaY:
return sorted.length % 2 !== 0 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2;
};
- dispathWheelEvent();
+ dispatchWheelEvent();
let frameCount = 0;
const frameTimes = [];
diff --git a/packages/core/src/sheets/styles.ts b/packages/core/src/sheets/styles.ts
index b9b7b8e19b..b4212c3ebf 100644
--- a/packages/core/src/sheets/styles.ts
+++ b/packages/core/src/sheets/styles.ts
@@ -71,7 +71,6 @@ export class Styles {
const id = Tools.generateRandomId(6);
this._styles[id] = data;
// update cache
-
this._cacheMap.set(styleObject, id);
return id;
diff --git a/packages/sheets/src/commands/commands/move-range.command.ts b/packages/sheets/src/commands/commands/move-range.command.ts
index 3a9c3d94f1..114aa06d31 100644
--- a/packages/sheets/src/commands/commands/move-range.command.ts
+++ b/packages/sheets/src/commands/commands/move-range.command.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import type { IAccessor, ICellData, ICommand, IMutationInfo, IRange, Nullable } from '@univerjs/core';
+import type { IAccessor, ICellData, ICommand, IMutationInfo, IRange, IStyleData, Nullable } from '@univerjs/core';
import type { IMoveRangeMutationParams } from '../mutations/move-range.mutation';
import type { ISetSelectionsOperationParams } from '../operations/selection.operation';
@@ -127,6 +127,7 @@ export interface IRangeUnit {
range: IRange;
}
+// eslint-disable-next-line max-lines-per-function
export function getMoveRangeUndoRedoMutations(
accessor: IAccessor,
from: IRangeUnit,
@@ -152,9 +153,15 @@ export function getMoveRangeUndoRedoMutations(
const fromCellValue = new ObjectMatrix<Nullable<ICellData>>();
const newFromCellValue = new ObjectMatrix<Nullable<ICellData>>();
+ const fromCellStyle = new ObjectMatrix<Nullable<IStyleData>>();
Range.foreach(fromRange, (row, col) => {
- fromCellValue.setValue(row, col, Tools.deepClone(fromCellMatrix.getValue(row, col)));
+ const cellData = fromCellMatrix.getValue(row, col);
+ fromCellValue.setValue(row, col, Tools.deepClone(cellData));
+ if (cellData) {
+ const style = workbook?.getStyles().get(cellData.s);
+ fromCellStyle.setValue(row, col, Tools.deepClone(style));
+ }
newFromCellValue.setValue(row, col, null);
});
const toCellValue = new ObjectMatrix<Nullable<ICellData>>();
@@ -168,7 +175,13 @@ export function getMoveRangeUndoRedoMutations(
const cellRange = cellToRange(row, col);
const relativeRange = Rectangle.getRelativeRange(cellRange, fromRange);
const range = Rectangle.getPositionRange(relativeRange, toRange);
- newToCellValue.setValue(range.startRow, range.startColumn, Tools.deepClone(fromCellMatrix.getValue(row, col)));
+
+ const styleValue = Tools.deepClone(fromCellStyle.getValue(row, col));
+ const cellValue = Tools.deepClone(fromCellValue.getValue(row, col));
+ if (cellValue && styleValue) {
+ cellValue.s = styleValue;
+ }
+ newToCellValue.setValue(range.startRow, range.startColumn, cellValue);
});
const doMoveRangeMutation: IMoveRangeMutationParams = {