Skip to content

Commit

Permalink
fix: insert row col with effect freeze (#1464)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhongz committed Mar 5, 2024
1 parent bd8c5df commit 8de2b10
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion packages/sheets-ui/src/controllers/freeze.controller.ts
Expand Up @@ -29,6 +29,8 @@ import {
import type { IMouseEvent, IPointerEvent, IScrollObserverParam, Viewport } from '@univerjs/engine-render';
import { CURSOR_TYPE, IRenderManagerService, Rect, TRANSFORM_CHANGE_OBSERVABLE_TYPE, Vector2 } from '@univerjs/engine-render';
import type {
IInsertColCommandParams,
IInsertRowCommandParams,
IMoveColsCommandParams,
IMoveRowsCommandParams,
IRemoveRowColCommandParams,
Expand All @@ -39,8 +41,10 @@ import type {
ISetWorksheetRowHeightMutationParams,
} from '@univerjs/sheets';
import {
InsertColCommand,
InsertRangeMoveDownCommand,
InsertRangeMoveRightCommand,
InsertRowCommand,
MoveColsCommand,
MoveRowsCommand,
RemoveColCommand,
Expand Down Expand Up @@ -153,7 +157,6 @@ export class FreezeController extends Disposable {

override dispose(): void {
super.dispose();
this._clearFreeze();
}

private _initialize() {
Expand Down Expand Up @@ -1163,6 +1166,36 @@ export class FreezeController extends Disposable {
};
};

if (command.id === InsertRowCommand.id) {
const params = command.params as IInsertRowCommandParams;
const range = params.range;
const insertCount = range.endRow - range.startRow + 1;
if (range.startRow <= freeze.startRow) {
const newFreeze: IFreeze = {
...freeze,
startRow: Math.max(1, freeze.startRow + insertCount),
ySplit: Math.max(1, freeze.ySplit + insertCount),
};

return createFreezeMutationAndRefresh(newFreeze);
}
}

if (command.id === InsertColCommand.id) {
const params = command.params as IInsertColCommandParams;
const range = params.range;
const insertCount = range.endColumn - range.startColumn + 1;
if (range.startColumn <= freeze.startColumn) {
const newFreeze: IFreeze = {
...freeze,
startColumn: Math.max(1, freeze.startColumn + insertCount),
xSplit: Math.max(1, freeze.xSplit + insertCount),
};

return createFreezeMutationAndRefresh(newFreeze);
}
}

if (command.id === MoveColsCommand.id) {
const selections = this._selectionManagerService.getSelections();
const {
Expand Down

0 comments on commit 8de2b10

Please sign in to comment.