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
feat(facade): add `isCellEditing` and optimize `endEditingAsync` and `startEditing` in FWorkbbok api (#6041)
wpxp12345689815924b198
diff --git a/packages/sheets-ui/src/facade/f-workbook.ts b/packages/sheets-ui/src/facade/f-workbook.tsindex 12a16958b5..3a362858c9 100644--- a/packages/sheets-ui/src/facade/f-workbook.ts+++ b/packages/sheets-ui/src/facade/f-workbook.ts@@ -22,7 +22,7 @@ import type { IDialogPartMethodOptions, ISidebarMethodOptions } from '@univerjs/import type { ICellEventParam } from './f-event';import { awaitTime, ICommandService, ILogService, toDisposable } from '@univerjs/core';import { DeviceInputEventType, IRenderManagerService } from '@univerjs/engine-render';-import { DragManagerService, HoverManagerService, ISheetSelectionRenderService, SetCellEditVisibleOperation, SHEET_VIEW_KEY, SheetScrollManagerService } from '@univerjs/sheets-ui';+import { DragManagerService, HoverManagerService, IEditorBridgeService, ISheetSelectionRenderService, SetCellEditVisibleOperation, SHEET_VIEW_KEY, SheetScrollManagerService } from '@univerjs/sheets-ui';import { FWorkbook } from '@univerjs/sheets/facade';import { IDialogService, ISidebarService, KeyCode } from '@univerjs/ui';import { filter } from 'rxjs';@@ -215,11 +215,23 @@ export interface IFWorkbookSheetsUIMixin {* @example* ```ts* const fWorkbook = univerAPI.getActiveWorkbook();- * await fWorkbook.endEditingAsync(false);+ * await fWorkbook.abortEditingAsync();* ```*/abortEditingAsync(): Promise<boolean>;+ /**+ * Check if the current active cell is in editing state+ * @returns {boolean} True if the current active cell is in editing state, false otherwise+ * @example+ * ```ts+ * const fWorkbook = univerAPI.getActiveWorkbook();+ * const isEditing = fWorkbook.isCellEditing();+ * console.log(isEditing);+ * ```+ */+ isCellEditing(): boolean;+/*** Get scroll state of specified sheet.* @param {string} sheetId - sheet id@@ -427,6 +439,12 @@ export class FWorkbookSheetsUIMixin extends FWorkbook implements IFWorkbookSheetoverride startEditing(): boolean {const commandService = this._injector.get(ICommandService);+ const editorBridgeService = this._injector.get(IEditorBridgeService);++ if (editorBridgeService.isVisible().visible) {+ return true;+ }+return commandService.syncExecuteCommand(SetCellEditVisibleOperation.id, {eventType: DeviceInputEventType.Dblclick,unitId: this._workbook.getUnitId(),@@ -436,12 +454,16 @@ export class FWorkbookSheetsUIMixin extends FWorkbook implements IFWorkbookSheetoverride async endEditing(save?: boolean): Promise<boolean> {const commandService = this._injector.get(ICommandService);- commandService.syncExecuteCommand(SetCellEditVisibleOperation.id, {- eventType: DeviceInputEventType.Keyboard,- keycode: save ? KeyCode.ENTER : KeyCode.ESC,- visible: false,- unitId: this._workbook.getUnitId(),- } as IEditorBridgeServiceVisibleParam);+ const editorBridgeService = this._injector.get(IEditorBridgeService);++ if (editorBridgeService.isVisible().visible) {+ commandService.syncExecuteCommand(SetCellEditVisibleOperation.id, {+ eventType: DeviceInputEventType.Keyboard,+ keycode: save ? KeyCode.ENTER : KeyCode.ESC,+ visible: false,+ unitId: this._workbook.getUnitId(),+ } as IEditorBridgeServiceVisibleParam);+ }// wait for the async cell edit operation to completeawait awaitTime(0);@@ -456,6 +478,11 @@ export class FWorkbookSheetsUIMixin extends FWorkbook implements IFWorkbookSheetreturn this.endEditingAsync(false);}+ override isCellEditing(): boolean {+ const editorBridgeService = this._injector.get(IEditorBridgeService);+ return editorBridgeService.isVisible().visible;+ }+/*** Get scroll state of specified sheet.* @param {string} sheetId - sheet id