Skip to content

Commit

Permalink
fix: #4551
Browse files Browse the repository at this point in the history
  • Loading branch information
weird94 committed Feb 11, 2025
1 parent d2697a8 commit 9d694aa
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

/* eslint-disable max-lines-per-function */

import type { DocumentDataModel, ICellData, ICommandInfo, IDisposable, IDocumentBody, IDocumentData, IDocumentStyle, IStyleData, Nullable, Styles, Workbook } from '@univerjs/core';
import type { DocumentDataModel, ICellData, ICommandInfo, IDisposable, IDocumentBody, IDocumentData, IDocumentStyle, IMutationInfo, IStyleData, Nullable, Styles, Workbook } from '@univerjs/core';
import type { IRichTextEditingMutationParams } from '@univerjs/docs';
import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';
import type { WorkbookSelectionModel } from '@univerjs/sheets';
import type { MutationsAffectRange, WorkbookSelectionModel } from '@univerjs/sheets';

import type { IEditorBridgeServiceVisibleParam } from '../../services/editor-bridge.service';
import {
Expand Down Expand Up @@ -55,7 +55,7 @@ import {
IRenderManagerService,
} from '@univerjs/engine-render';

import { COMMAND_LISTENER_SKELETON_CHANGE, REF_SELECTIONS_ENABLED, SetRangeValuesCommand, SetSelectionsOperation, SetWorksheetActivateCommand, SetWorksheetActiveOperation, SheetInterceptorService, SheetsSelectionsService } from '@univerjs/sheets';
import { adjustRangeOnMutation, COMMAND_LISTENER_SKELETON_CHANGE, InsertColMutation, InsertRowMutation, MoveColsMutation, MoveRowsMutation, REF_SELECTIONS_ENABLED, RemoveColMutation, RemoveRowMutation, SetRangeValuesCommand, SetSelectionsOperation, SetWorksheetActivateCommand, SetWorksheetActiveOperation, SheetInterceptorService, SheetsSelectionsService } from '@univerjs/sheets';
import { KeyCode } from '@univerjs/ui';
import { distinctUntilChanged, filter } from 'rxjs';
import { getEditorObject } from '../../basics/editor/get-editor-object';
Expand Down Expand Up @@ -225,6 +225,31 @@ export class EditingRenderController extends Disposable implements IRenderModule
if (!commandList.has(commandInfo.id)) {
return;
}
switch (commandInfo.id) {
case MoveRowsMutation.id:
case MoveColsMutation.id:
case RemoveColMutation.id:
case RemoveRowMutation.id:
case InsertColMutation.id:
case InsertRowMutation.id:
{
const editLocation = this._editorBridgeService.getEditLocation();
if (!editLocation) break;
const currentRange = {
startRow: editLocation.row,
startColumn: editLocation.column,
endRow: editLocation.row,
endColumn: editLocation.column,
};
const newRange = adjustRangeOnMutation(currentRange, commandInfo as IMutationInfo<MutationsAffectRange>);
if (!newRange) break;
const newRow = newRange.startRow;
const newColumn = newRange.startColumn;
this._editorBridgeService.updateEditLocation(newRow, newColumn);
break;
}
}

this._sheetCellEditorResizeService.resizeCellEditor(() => {
this._textSelectionManagerService.refreshSelection({
unitId: DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
Expand Down
11 changes: 11 additions & 0 deletions packages/sheets-ui/src/services/editor-bridge.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export interface IEditorBridgeService {
getEditCellState(): Readonly<Nullable<IEditorBridgeServiceParam>>;
getEditCellLayout(): Readonly<Nullable<ICellEditorLayout>>;
getEditLocation(): Readonly<Nullable<ICellEditorState>>;
updateEditLocation(row: number, col: number): void;
// Gets the DocumentDataModel of the latest table cell based on the latest cell contents
getLatestEditCellState(): Readonly<Nullable<IEditorBridgeServiceParam>>;
/**
Expand Down Expand Up @@ -290,6 +291,16 @@ export class EditorBridgeService extends Disposable implements IEditorBridgeServ
return this._currentEditCellState;
}

updateEditLocation(row: number, column: number) {
if (this._currentEditCellState) {
this._currentEditCellState = {
...this._currentEditCellState,
row,
column,
};
}
}

// eslint-disable-next-line max-lines-per-function
getLatestEditCellState() {
const currentEditCell = this._currentEditCell;
Expand Down

0 comments on commit 9d694aa

Please sign in to comment.