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: need to empty formula bar when press backspace (#841)
Ran Luo0940ccd3c7c3
diff --git a/packages/sheets-ui/src/commands/operations/activate-cell-edit.operation.ts b/packages/sheets-ui/src/commands/operations/activate-cell-edit.operation.tsindex a19a43a615..28b84b96d1 100644--- a/packages/sheets-ui/src/commands/operations/activate-cell-edit.operation.ts+++ b/packages/sheets-ui/src/commands/operations/activate-cell-edit.operation.ts@@ -17,16 +17,16 @@import type { IOperation } from '@univerjs/core';import { CommandType } from '@univerjs/core';-import type { IEditorBridgeServiceParam } from '../../services/editor-bridge.service';+import type { ICurrentEditCellParam } from '../../services/editor-bridge.service';import { IEditorBridgeService } from '../../services/editor-bridge.service';-export const SetActivateCellEditOperation: IOperation<IEditorBridgeServiceParam> = {+export const SetActivateCellEditOperation: IOperation<ICurrentEditCellParam> = {id: 'sheet.operation.set-activate-cell-edit',type: CommandType.OPERATION,handler: (accessor, params) => {const editorBridgeService = accessor.get(IEditorBridgeService);- editorBridgeService.setState(params!);+ editorBridgeService.setEditCell(params);return true;},diff --git a/packages/sheets-ui/src/controllers/editor-bridge.controller.ts b/packages/sheets-ui/src/controllers/editor-bridge.controller.tsindex 4c7c0ce572..0cac014178 100644--- a/packages/sheets-ui/src/controllers/editor-bridge.controller.ts+++ b/packages/sheets-ui/src/controllers/editor-bridge.controller.ts@@ -15,22 +15,8 @@*/import type { ICommandInfo, IExecutionOptions, Nullable } from '@univerjs/core';-import {- DOCS_NORMAL_EDITOR_UNIT_ID_KEY,- ICommandService,- IUniverInstanceService,- LifecycleStages,- makeCellToSelection,- OnLifecycle,- RxDisposable,- ThemeService,-} from '@univerjs/core';-import {- DeviceInputEventType,- fixLineWidthByScale,- getCanvasOffsetByEngine,- IRenderManagerService,-} from '@univerjs/engine-render';+import { ICommandService, IUniverInstanceService, LifecycleStages, OnLifecycle, RxDisposable } from '@univerjs/core';+import { DeviceInputEventType, IRenderManagerService } from '@univerjs/engine-render';import type { ISelectionWithStyle } from '@univerjs/sheets';import {COMMAND_LISTENER_SKELETON_CHANGE,@@ -44,23 +30,18 @@ import { merge, takeUntil } from 'rxjs';import { SetActivateCellEditOperation } from '../commands/operations/activate-cell-edit.operation';import { SetCellEditVisibleOperation } from '../commands/operations/cell-edit.operation';import { IEditorBridgeService } from '../services/editor-bridge.service';-import { ISelectionRenderService } from '../services/selection/selection-render.service';import { SheetSkeletonManagerService } from '../services/sheet-skeleton-manager.service';import { getSheetObject } from './utils/component-tools';@OnLifecycle(LifecycleStages.Rendered, EditorBridgeController)export class EditorBridgeController extends RxDisposable {- // private _lastEditorLocation: Nullable<IEditorLocation> = null;-constructor(@Inject(SheetSkeletonManagerService) private readonly _sheetSkeletonManagerService: SheetSkeletonManagerService,@IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService,@ICommandService private readonly _commandService: ICommandService,@IRenderManagerService private readonly _renderManagerService: IRenderManagerService,@IEditorBridgeService private readonly _editorBridgeService: IEditorBridgeService,- @Inject(SelectionManagerService) private readonly _selectionManagerService: SelectionManagerService,- @ISelectionRenderService private readonly _selectionRenderService: ISelectionRenderService,- @Inject(ThemeService) private readonly _themeService: ThemeService+ @Inject(SelectionManagerService) private readonly _selectionManagerService: SelectionManagerService) {super();@@ -77,12 +58,7 @@ export class EditorBridgeController extends RxDisposable {}private _initSelectionChangeListener() {- merge(- this._selectionManagerService.selectionMoveEnd$,- this._selectionManagerService.selectionMoveStart$,- // The cell size will change after edit by zen-editor, so need to refresh state(endY AND endX).- this._editorBridgeService.refreshState$- )+ merge(this._selectionManagerService.selectionMoveEnd$, this._selectionManagerService.selectionMoveStart$).pipe(takeUntil(this.dispose$)).subscribe((params) => this._handleSelectionListener(params));}@@ -90,9 +66,7 @@ export class EditorBridgeController extends RxDisposable {private _handleSelectionListener(params: Nullable<ISelectionWithStyle[]>) {const current = this._selectionManagerService.getCurrent();- /**- * The editor only responds to regular selections.- */+ // The editor only responds to regular selections.if (current?.pluginName !== NORMAL_SELECTION_PLUGIN_NAME) {return;}@@ -103,17 +77,11 @@ export class EditorBridgeController extends RxDisposable {const currentSkeleton = this._sheetSkeletonManagerService.getCurrent();- const sheetObject = this._getSheetObject();-- if (currentSkeleton == null || sheetObject == null) {+ if (currentSkeleton == null) {return;}- const { skeleton, unitId, sheetId } = currentSkeleton;-- const { scene, engine } = sheetObject;-- if (params == null || params.length === 0 || skeleton == null || params[params.length - 1] == null) {+ if (params == null || params.length === 0 || params[params.length - 1] == null) {return;}@@ -122,88 +90,22 @@ export class EditorBridgeController extends RxDisposable {return;}- const { startRow, startColumn } = primary;- const primaryWithCoord = this._selectionRenderService.convertCellRangeToInfo(primary);- if (primaryWithCoord == null) {- return;- }+ const sheetObject = this._getSheetObject();- const actualRangeWithCoord = makeCellToSelection(primaryWithCoord);- if (actualRangeWithCoord == null) {+ if (sheetObject == null) {return;}- const canvasOffset = getCanvasOffsetByEngine(engine);-- let { startX, startY, endX, endY } = actualRangeWithCoord;-- const { scaleX, scaleY } = scene.getAncestorScale();-- const { scaleX: precisionScaleX, scaleY: precisionScaleY } = scene.getPrecisionScale();-- const scrollXY = scene.getScrollXY(this._selectionRenderService.getViewPort());- startX = fixLineWidthByScale(skeleton.convertTransformToOffsetX(startX, scaleX, scrollXY), precisionScaleX);- startY = fixLineWidthByScale(skeleton.convertTransformToOffsetY(startY, scaleY, scrollXY), precisionScaleY);- endX = fixLineWidthByScale(skeleton.convertTransformToOffsetX(endX, scaleX, scrollXY), precisionScaleX);- endY = fixLineWidthByScale(skeleton.convertTransformToOffsetY(endY, scaleY, scrollXY), precisionScaleY);-- const workbook = this._currentUniverService.getCurrentUniverSheetInstance();- const worksheet = workbook.getActiveSheet();- const location = {- workbook,- worksheet,- unitId: workbook.getUnitId(),- subUnitId: worksheet.getSheetId(),- row: startRow,- col: startColumn,- };-- const cell = this._editorBridgeService.interceptor.fetchThroughInterceptors(- this._editorBridgeService.interceptor.getInterceptPoints().BEFORE_CELL_EDIT- )(worksheet.getCell(startRow, startColumn), location);+ const { unitId, sheetId } = currentSkeleton;- let documentLayoutObject = cell && skeleton.getCellDocumentModelWithFormula(cell);-- if (!documentLayoutObject || documentLayoutObject.documentModel == null) {- documentLayoutObject = skeleton.getBlankCellDocumentModel(cell);- }-- documentLayoutObject.documentModel?.setZoomRatio(Math.max(scaleX, scaleY));-- if (cell?.isInArrayFormulaRange === true) {- const body = documentLayoutObject.documentModel?.getBody();- if (body) {- body.textRuns = [- {- st: 0,- ed: body.dataStream.length - 2,- ts: {- cl: {- rgb: this._themeService.getCurrentTheme().textColorSecondary,- },- },- },- ];- }- }+ const { scene, engine } = sheetObject;this._commandService.executeCommand(SetActivateCellEditOperation.id, {- position: {- startX,- startY,- endX,- endY,- },- scaleX,- scaleY,- canvasOffset,- row: startRow,- column: startColumn,+ scene,+ engine,+ primary,unitId,sheetId,- documentLayoutObject,- editorUnitId: DOCS_NORMAL_EDITOR_UNIT_ID_KEY,- isInArrayFormulaRange: cell?.isInArrayFormulaRange,});}diff --git a/packages/sheets-ui/src/controllers/editor/end-edit.controller.ts b/packages/sheets-ui/src/controllers/editor/end-edit.controller.tsindex d4f8691b62..c58ff1fc81 100644--- a/packages/sheets-ui/src/controllers/editor/end-edit.controller.ts+++ b/packages/sheets-ui/src/controllers/editor/end-edit.controller.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { DocumentDataModel, ICellData, ICommandInfo, IDocumentBody, Nullable, Observer } from '@univerjs/core';+import type { ICellData, ICommandInfo, IDocumentBody, Nullable, Observer } from '@univerjs/core';import {DEFAULT_EMPTY_DOCUMENT_VALUE,Direction,@@ -166,17 +166,13 @@ export class EndEditController extends Disposable {return;}- const state = this._editorBridgeService.getState();+ const editCellState = this._editorBridgeService.getEditCellState();- if (state == null) {+ if (editCellState == null) {return;}- const { unitId, sheetId, row, column, documentLayoutObject } = state;-- if (documentLayoutObject == null) {- return;- }+ const { unitId, sheetId, row, column, documentLayoutObject } = editCellState;this._moveCursor(keycode);@@ -375,11 +371,15 @@ export function getCellDataByInput() {cellData = Tools.deepClone(cellData);- const documentModel = documentLayoutObject.documentModel as DocumentDataModel;+ const { documentModel } = documentLayoutObject;++ if (documentModel == null) {+ return null;+ }const snapshot = documentModel.getSnapshot();- const body = snapshot.body;+ const { body } = snapshot;if (body == null) {return null;diff --git a/packages/sheets-ui/src/controllers/editor/formula-editor.controller.ts b/packages/sheets-ui/src/controllers/editor/formula-editor.controller.tsindex 459013e9a0..e640f233a1 100644--- a/packages/sheets-ui/src/controllers/editor/formula-editor.controller.ts+++ b/packages/sheets-ui/src/controllers/editor/formula-editor.controller.ts@@ -42,6 +42,8 @@ import {VIEWPORT_KEY,} from '@univerjs/docs';import { DeviceInputEventType, IRenderManagerService, ScrollBar } from '@univerjs/engine-render';+import type { IMoveRangeMutationParams, ISetRangeValuesMutationParams } from '@univerjs/sheets';+import { MoveRangeMutation, SetRangeValuesMutation } from '@univerjs/sheets';import { Inject } from '@wendellhu/redi';import { takeUntil } from 'rxjs';@@ -228,12 +230,12 @@ export class FormulaEditorController extends RxDisposable {// Sync cell content to formula editor bar when sheet selection changed.private _syncFormulaEditorContent() {- this._editorBridgeService.state$.pipe(takeUntil(this.dispose$)).subscribe((param) => {- if (param == null || this._editorBridgeService.isForceKeepVisible()) {+ this._editorBridgeService.currentEditCellState$.pipe(takeUntil(this.dispose$)).subscribe((editCellState) => {+ if (editCellState == null || this._editorBridgeService.isForceKeepVisible()) {return;}- this._editorSyncHandler(param);+ this._editorSyncHandler(editCellState);});this._editorBridgeService.visible$.pipe(takeUntil(this.dispose$)).subscribe((state) => {@@ -241,13 +243,13 @@ export class FormulaEditorController extends RxDisposable {return;}- const param = this._editorBridgeService.getState();+ const cellEditState = this._editorBridgeService.getLatestEditCellState();- if (param == null) {+ if (cellEditState == null) {return;}- this._editorSyncHandler(param);+ this._editorSyncHandler(cellEditState);});}@@ -316,6 +318,48 @@ export class FormulaEditorController extends RxDisposable {}}));++ // Update formula bar content when you call SetRangeValuesMutation and MoveRangeMutation.+ const needUpdateFormulaEditorContentCommandList = [SetRangeValuesMutation.id, MoveRangeMutation.id];+ this.disposeWithMe(+ this._commandService.onCommandExecuted((command: ICommandInfo) => {+ if (needUpdateFormulaEditorContentCommandList.includes(command.id)) {+ const editCellState = this._editorBridgeService.getLatestEditCellState();++ if (editCellState == null) {+ return;+ }++ let needUpdate = false;++ const { row, column } = editCellState;++ if (command.id === SetRangeValuesMutation.id && command.params) {+ const params = command.params as ISetRangeValuesMutationParams;+ if (params.cellValue?.[row]?.[column]) {+ needUpdate = true;+ }+ } else if (command.id === MoveRangeMutation.id && command.params) {+ const params = command.params as IMoveRangeMutationParams;+ if (params.to.value?.[row]?.[column]) {+ needUpdate = true;+ }+ }++ if (needUpdate) {+ const body = editCellState.documentLayoutObject.documentModel?.getBody();++ if (body == null) {+ return;+ }+ const { dataStream, paragraphs = [] } = body;+ this._syncContentAndRender(DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, dataStream, paragraphs);+ // handle weather need to show scroll bar.+ this._autoScroll();+ }+ }+ })+ );}private _syncContentAndRender(diff --git a/packages/sheets-ui/src/controllers/editor/start-edit.controller.ts b/packages/sheets-ui/src/controllers/editor/start-edit.controller.tsindex e136c790f4..f5224c18b0 100644--- a/packages/sheets-ui/src/controllers/editor/start-edit.controller.ts+++ b/packages/sheets-ui/src/controllers/editor/start-edit.controller.ts@@ -131,7 +131,7 @@ export class StartEditController extends Disposable {renderConfig.document.onPointerDownObserver.add(() => {// fix https://github.com/dream-num/univer/issues/628, need to recalculate the cell editor size after it acquire focus.if (this._editorBridgeService.isVisible()) {- const param = this._editorBridgeService.getState();+ const param = this._editorBridgeService.getEditCellState();const unitId = this._editorBridgeService.getCurrentEditorId();if (param == null || unitId == null) {@@ -160,12 +160,12 @@ export class StartEditController extends Disposable {}private _initialEditFocusListener() {- this._onInputSubscription = this._editorBridgeService.state$.subscribe((param) => {- if (param == null || this._editorBridgeService.isForceKeepVisible()) {+ this._onInputSubscription = this._editorBridgeService.currentEditCellState$.subscribe((editCellState) => {+ if (editCellState == null || this._editorBridgeService.isForceKeepVisible()) {return;}- const { position, documentLayoutObject, scaleX, editorUnitId } = param;+ const { position, documentLayoutObject, scaleX, editorUnitId } = editCellState;const editorObject = this._getEditorObject();@@ -181,8 +181,6 @@ export class StartEditController extends Disposable {documentModel!.updateDocumentId(editorUnitId);- // documentModel!.updateDocumentDataMargin(paddingData);-if (wrapStrategy === WrapStrategy.WRAP && angle === 0) {documentModel!.updateDocumentDataPageSize((endX - startX) / scaleX);}@@ -469,9 +467,9 @@ export class StartEditController extends Disposable {return;}- const state = this._editorBridgeService.getState();+ const editCellState = this._editorBridgeService.getEditCellState();- if (state == null) {+ if (editCellState == null) {return;}@@ -484,7 +482,7 @@ export class StartEditController extends Disposable {editorUnitId,unitId,isInArrayFormulaRange = false,- } = state;+ } = editCellState;const editorObject = this._getEditorObject();@@ -649,7 +647,7 @@ export class StartEditController extends Disposable {return;}- const param = this._editorBridgeService.getState();+ const param = this._editorBridgeService.getEditCellState();if (param == null) {return;}diff --git a/packages/sheets-ui/src/services/editor-bridge.service.ts b/packages/sheets-ui/src/services/editor-bridge.service.tsindex 60bb068494..594380be6c 100644--- a/packages/sheets-ui/src/services/editor-bridge.service.ts+++ b/packages/sheets-ui/src/services/editor-bridge.service.ts@@ -14,24 +14,43 @@* limitations under the License.*/-import type { ICellDataForSheetInterceptor, IPosition, Nullable } from '@univerjs/core';-import { createInterceptorKey, Disposable, InterceptorManager, toDisposable } from '@univerjs/core';-import type { IDocumentLayoutObject } from '@univerjs/engine-render';-import { DeviceInputEventType } from '@univerjs/engine-render';-import type { ISelectionWithStyle, ISheetLocation } from '@univerjs/sheets';-import { SelectionManagerService } from '@univerjs/sheets';+import type { ICellDataForSheetInterceptor, IPosition, ISelectionCell, Nullable } from '@univerjs/core';+import {+ createInterceptorKey,+ Disposable,+ DOCS_NORMAL_EDITOR_UNIT_ID_KEY,+ InterceptorManager,+ IUniverInstanceService,+ makeCellToSelection,+ ThemeService,+ toDisposable,+} from '@univerjs/core';+import type { Engine, IDocumentLayoutObject, Scene } from '@univerjs/engine-render';+import { DeviceInputEventType, fixLineWidthByScale, getCanvasOffsetByEngine } from '@univerjs/engine-render';+import type { ISheetLocation } from '@univerjs/sheets';import type { KeyCode } from '@univerjs/ui';import type { IDisposable } from '@wendellhu/redi';import { createIdentifier, Inject } from '@wendellhu/redi';import type { Observable } from 'rxjs';import { BehaviorSubject } from 'rxjs';+import { ISelectionRenderService } from './selection/selection-render.service';+import { SheetSkeletonManagerService } from './sheet-skeleton-manager.service';+export interface IEditorBridgeServiceVisibleParam {visible: boolean;eventType: DeviceInputEventType;keycode?: KeyCode;}+export interface ICurrentEditCellParam {+ scene: Scene;+ engine: Engine;+ unitId: string;+ sheetId: string;+ primary: ISelectionCell;+}+export interface IEditorBridgeServiceParam {unitId: string;sheetId: string;@@ -45,19 +64,23 @@ export interface IEditorBridgeServiceParam {editorUnitId: string;isInArrayFormulaRange?: Nullable<boolean>;}+const BEFORE_CELL_EDIT = createInterceptorKey<ICellDataForSheetInterceptor, ISheetLocation>('BEFORE_CELL_EDIT');const AFTER_CELL_EDIT = createInterceptorKey<ICellDataForSheetInterceptor, ISheetLocation>('AFTER_CELL_EDIT');+export interface IEditorBridgeService {- refreshState$: Observable<Nullable<ISelectionWithStyle[]>>;- state$: Observable<Nullable<IEditorBridgeServiceParam>>;+ currentEditCellState$: Observable<Nullable<IEditorBridgeServiceParam>>;visible$: Observable<IEditorBridgeServiceVisibleParam>;interceptor: InterceptorManager<{BEFORE_CELL_EDIT: typeof BEFORE_CELL_EDIT;AFTER_CELL_EDIT: typeof AFTER_CELL_EDIT;}>;dispose(): void;- setState(param: IEditorBridgeServiceParam): void;- getState(): Readonly<Nullable<IEditorBridgeServiceParam>>;+ refreshEditCellState(): void;+ setEditCell(param: ICurrentEditCellParam): void;+ getEditCellState(): Readonly<Nullable<IEditorBridgeServiceParam>>;+ // Gets the DocumentDataModel of the latest table cell based on the latest cell contents+ getLatestEditCellState(): Readonly<Nullable<IEditorBridgeServiceParam>>;changeVisible(param: IEditorBridgeServiceVisibleParam): void;changeEditorDirty(dirtyStatus: boolean): void;getEditorDirty(): boolean;@@ -69,7 +92,7 @@ export interface IEditorBridgeService {}export class EditorBridgeService extends Disposable implements IEditorBridgeService, IDisposable {- private _state: Nullable<IEditorBridgeServiceParam> = null;+ private _editorUnitId: string = DOCS_NORMAL_EDITOR_UNIT_ID_KEY;private _isForceKeepVisible: boolean = false;@@ -80,11 +103,10 @@ export class EditorBridgeService extends Disposable implements IEditorBridgeServeventType: DeviceInputEventType.Dblclick,};- private readonly _refreshState$ = new BehaviorSubject<Nullable<ISelectionWithStyle[]>>(null);- readonly refreshState$ = this._refreshState$.asObservable();-- private readonly _state$ = new BehaviorSubject<Nullable<IEditorBridgeServiceParam>>(null);- readonly state$ = this._state$.asObservable();+ private _currentEditCell: Nullable<ICurrentEditCellParam> = null;+ private _currentEditCellState: Nullable<IEditorBridgeServiceParam> = null;+ private readonly _currentEditCellState$ = new BehaviorSubject<Nullable<IEditorBridgeServiceParam>>(null);+ readonly currentEditCellState$ = this._currentEditCellState$.asObservable();private readonly _visible$ = new BehaviorSubject<IEditorBridgeServiceVisibleParam>(this._visible);readonly visible$ = this._visible$.asObservable();@@ -97,14 +119,21 @@ export class EditorBridgeService extends Disposable implements IEditorBridgeServAFTER_CELL_EDIT,});- constructor(@Inject(SelectionManagerService) private readonly _selectionManagerService: SelectionManagerService) {+ constructor(+ @Inject(SheetSkeletonManagerService) private readonly _sheetSkeletonManagerService: SheetSkeletonManagerService,+ @ISelectionRenderService private readonly _selectionRenderService: ISelectionRenderService,+ @Inject(ThemeService) private readonly _themeService: ThemeService,+ @IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService+ ) {super();+this.disposeWithMe(toDisposable(() => {- this._state$.complete();- this._state = null;+ this._currentEditCellState$.complete();+ this._currentEditCell = null;}));+this.disposeWithMe(toDisposable(this.interceptor.intercept(this.interceptor.getInterceptPoints().AFTER_CELL_EDIT, {@@ -124,24 +153,129 @@ export class EditorBridgeService extends Disposable implements IEditorBridgeServ);}- setState(param: IEditorBridgeServiceParam) {- this._state = param;+ refreshEditCellState() {+ const editCellState = this.getLatestEditCellState();+ this._currentEditCellState = editCellState;- this._state$.next(param);+ this._currentEditCellState$.next(editCellState);}- getState(): Readonly<Nullable<IEditorBridgeServiceParam>> {- return this._state;+ setEditCell(param: ICurrentEditCellParam) {+ this._currentEditCell = param;++ const editCellState = this.getLatestEditCellState();+ this._currentEditCellState = editCellState;++ this._currentEditCellState$.next(editCellState);}- refreshState() {- const selections = this._selectionManagerService.getSelections() as Nullable<ISelectionWithStyle[]>;+ getEditCellState(): Readonly<Nullable<IEditorBridgeServiceParam>> {+ return this._currentEditCellState;+ }++ getLatestEditCellState() {+ const currentEditCell = this._currentEditCell;+ if (currentEditCell == null) {+ return;+ }++ const currentSkeleton = this._sheetSkeletonManagerService.getCurrent();++ if (currentSkeleton == null) {+ return;+ }++ const { skeleton } = currentSkeleton;++ const { primary, unitId, sheetId, scene, engine } = currentEditCell;+ const { startRow, startColumn } = primary;+ const primaryWithCoord = this._selectionRenderService.convertCellRangeToInfo(primary);+ if (primaryWithCoord == null) {+ return;+ }++ const actualRangeWithCoord = makeCellToSelection(primaryWithCoord);+ if (actualRangeWithCoord == null) {+ return;+ }++ const canvasOffset = getCanvasOffsetByEngine(engine);++ let { startX, startY, endX, endY } = actualRangeWithCoord;++ const { scaleX, scaleY } = scene.getAncestorScale();++ const { scaleX: precisionScaleX, scaleY: precisionScaleY } = scene.getPrecisionScale();++ const scrollXY = scene.getScrollXY(this._selectionRenderService.getViewPort());+ startX = fixLineWidthByScale(skeleton.convertTransformToOffsetX(startX, scaleX, scrollXY), precisionScaleX);+ startY = fixLineWidthByScale(skeleton.convertTransformToOffsetY(startY, scaleY, scrollXY), precisionScaleY);+ endX = fixLineWidthByScale(skeleton.convertTransformToOffsetX(endX, scaleX, scrollXY), precisionScaleX);+ endY = fixLineWidthByScale(skeleton.convertTransformToOffsetY(endY, scaleY, scrollXY), precisionScaleY);++ const workbook = this._currentUniverService.getCurrentUniverSheetInstance();+ const worksheet = workbook.getActiveSheet();+ const location = {+ workbook,+ worksheet,+ unitId: workbook.getUnitId(),+ subUnitId: worksheet.getSheetId(),+ row: startRow,+ col: startColumn,+ };++ const cell = this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().BEFORE_CELL_EDIT)(+ worksheet.getCell(startRow, startColumn),+ location+ );++ let documentLayoutObject = cell && skeleton.getCellDocumentModelWithFormula(cell);++ if (!documentLayoutObject || documentLayoutObject.documentModel == null) {+ documentLayoutObject = skeleton.getBlankCellDocumentModel(cell);+ }++ documentLayoutObject.documentModel?.setZoomRatio(Math.max(scaleX, scaleY));++ if (cell?.isInArrayFormulaRange === true) {+ const body = documentLayoutObject.documentModel?.getBody();+ if (body) {+ body.textRuns = [+ {+ st: 0,+ ed: body.dataStream.length - 2,+ ts: {+ cl: {+ rgb: this._themeService.getCurrentTheme().textColorSecondary,+ },+ },+ },+ ];+ }+ }- this._refreshState$.next(selections);+ return {+ position: {+ startX,+ startY,+ endX,+ endY,+ },+ scaleX,+ scaleY,+ canvasOffset,+ row: startRow,+ column: startColumn,+ unitId,+ sheetId,+ documentLayoutObject,+ editorUnitId: this._editorUnitId,+ isInArrayFormulaRange: cell?.isInArrayFormulaRange,+ };}getCurrentEditorId() {- return this._state?.editorUnitId;+ return this._editorUnitId;}changeVisible(param: IEditorBridgeServiceVisibleParam) {diff --git a/packages/sheets-zen-editor/src/commands/commands/zen-editor.command.ts b/packages/sheets-zen-editor/src/commands/commands/zen-editor.command.tsindex c9bf38b1e2..ae408561ad 100644--- a/packages/sheets-zen-editor/src/commands/commands/zen-editor.command.ts+++ b/packages/sheets-zen-editor/src/commands/commands/zen-editor.command.ts@@ -47,7 +47,7 @@ export const CancelZenEditCommand: ICommand = {univerInstanceManager.focusUniverInstance(currentSheetInstance.getUnitId());- editorBridgeService.refreshState();+ editorBridgeService.refreshEditCellState();return true;},@@ -79,7 +79,7 @@ export const ConfirmZenEditCommand: ICommand = {univerInstanceManager.focusUniverInstance(currentSheetInstance.getUnitId());- editorBridgeService.refreshState();+ editorBridgeService.refreshEditCellState();return true;},diff --git a/packages/sheets-zen-editor/src/controllers/zen-editor.controller.ts b/packages/sheets-zen-editor/src/controllers/zen-editor.controller.tsindex 6f766dd737..3346774bef 100644--- a/packages/sheets-zen-editor/src/controllers/zen-editor.controller.ts+++ b/packages/sheets-zen-editor/src/controllers/zen-editor.controller.ts@@ -35,7 +35,7 @@ import {TextSelectionManagerService,VIEWPORT_KEY,} from '@univerjs/docs';-import { DeviceInputEventType, IRenderManagerService, ITextSelectionRenderManager } from '@univerjs/engine-render';+import { DeviceInputEventType, IRenderManagerService } from '@univerjs/engine-render';import { getEditorObject } from '@univerjs/sheets-ui';import type { IEditorBridgeServiceParam } from '@univerjs/sheets-ui/services/editor-bridge.service.js';import { IEditorBridgeService } from '@univerjs/sheets-ui/services/editor-bridge.service.js';@@ -57,7 +57,6 @@ export class ZenEditorController extends RxDisposable {@ICommandService private readonly _commandService: ICommandService,@IZenZoneService private readonly _zenZoneService: IZenZoneService,@IEditorBridgeService private readonly _editorBridgeService: IEditorBridgeService,- @ITextSelectionRenderManager private readonly _textSelectionRenderManager: ITextSelectionRenderManager,@IUndoRedoService private readonly _undoRedoService: IUndoRedoService,@Inject(TextSelectionManagerService) private readonly _textSelectionManagerService: TextSelectionManagerService,@Inject(DocSkeletonManagerService) private readonly _docSkeletonManagerService: DocSkeletonManagerService,@@ -162,13 +161,13 @@ export class ZenEditorController extends RxDisposable {});}- const param = this._editorBridgeService.getState();+ const editCellState = this._editorBridgeService.getLatestEditCellState();- if (param == null) {+ if (editCellState == null) {return;}- this._editorSyncHandler(param);+ this._editorSyncHandler(editCellState);const textRanges = [{diff --git a/packages/sheets/src/commands/commands/clear-selection-content.command.ts b/packages/sheets/src/commands/commands/clear-selection-content.command.tsindex ed59494171..91d8e320b8 100644--- a/packages/sheets/src/commands/commands/clear-selection-content.command.ts+++ b/packages/sheets/src/commands/commands/clear-selection-content.command.ts@@ -35,7 +35,9 @@ import { SetRangeValuesMutation, SetRangeValuesUndoMutationFactory } from '../mu*/export const ClearSelectionContentCommand: ICommand = {id: 'sheet.command.clear-selection-content',+type: CommandType.COMMAND,+handler: async (accessor: IAccessor) => {const univerInstanceService = accessor.get(IUniverInstanceService);const commandService = accessor.get(ICommandService);diff --git a/packages/sheets/src/commands/commands/remove-row-col.command.ts b/packages/sheets/src/commands/commands/remove-row-col.command.tsindex 8fc1b02b42..d0652e7e67 100644--- a/packages/sheets/src/commands/commands/remove-row-col.command.ts+++ b/packages/sheets/src/commands/commands/remove-row-col.command.ts@@ -54,7 +54,9 @@ export const RemoveRowCommandId = 'sheet.command.remove-row';*/export const RemoveRowCommand: ICommand = {type: CommandType.COMMAND,+id: RemoveRowCommandId,+handler: async (accessor: IAccessor, params?: IRemoveRowColCommandParams) => {const selectionManagerService = accessor.get(SelectionManagerService);const sheetInterceptorService = accessor.get(SheetInterceptorService);diff --git a/packages/sheets/src/commands/mutations/remove-row-col.mutation.ts b/packages/sheets/src/commands/mutations/remove-row-col.mutation.tsindex 26b35b5f5c..ab18ae0781 100644--- a/packages/sheets/src/commands/mutations/remove-row-col.mutation.ts+++ b/packages/sheets/src/commands/mutations/remove-row-col.mutation.ts@@ -48,7 +48,9 @@ export const RemoveRowsUndoMutationFactory = (export const RemoveRowMutation: IMutation<IRemoveRowsMutationParams> = {id: 'sheet.mutation.remove-rows',+type: CommandType.MUTATION,+handler: (accessor, params) => {const univerInstanceService = accessor.get(IUniverInstanceService);const universheet = univerInstanceService.getUniverSheetInstance(params.unitId);