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(sheets-ui): formula-editor edit error (#4603)

zhangw155970885262
diff --git a/e2e/visual-comparison/sheets/sheets-switching-render-unit.spec.ts-snapshots/switching-render-unit-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-switching-render-unit.spec.ts-snapshots/switching-render-unit-ci-chromium-linux.png
index 53903187ad..2472d13d65 100644
Binary files a/e2e/visual-comparison/sheets/sheets-switching-render-unit.spec.ts-snapshots/switching-render-unit-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-switching-render-unit.spec.ts-snapshots/switching-render-unit-ci-chromium-linux.png differ
diff --git a/packages-experimental/uniui/src/views/uni-toolbar/UniFormulaBar.tsx b/packages-experimental/uniui/src/views/uni-toolbar/UniFormulaBar.tsx
index 3efaf8b71e..feff83d3d3 100644
--- a/packages-experimental/uniui/src/views/uni-toolbar/UniFormulaBar.tsx
+++ b/packages-experimental/uniui/src/views/uni-toolbar/UniFormulaBar.tsx
@@ -15,12 +15,12 @@
*/
import type { Nullable, Workbook } from '@univerjs/core';
-import { BooleanNumber, DEFAULT_EMPTY_DOCUMENT_VALUE, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DocumentFlavor, HorizontalAlign, IPermissionService, IUniverInstanceService, Rectangle, ThemeService, UniverInstanceType, useDependency, useObservable, VerticalAlign, WrapStrategy } from '@univerjs/core';
+import { BooleanNumber, DEFAULT_EMPTY_DOCUMENT_VALUE, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DocumentFlavor, HorizontalAlign, ICommandService, IPermissionService, IUniverInstanceService, Rectangle, ThemeService, UniverInstanceType, useDependency, useObservable, VerticalAlign, WrapStrategy } from '@univerjs/core';
// import { TextEditor } from '@univerjs/docs-ui';
import { DeviceInputEventType } from '@univerjs/engine-render';
import { CheckMarkSingle, CloseSingle, FxSingle } from '@univerjs/icons';
import { RangeProtectionPermissionEditPoint, RangeProtectionRuleModel, SheetsSelectionsService, WorkbookEditablePermission, WorksheetEditPermission, WorksheetProtectionRuleModel, WorksheetSetCellValuePermission } from '@univerjs/sheets';
-import { IEditorBridgeService, IFormulaEditorManagerService, useActiveWorkbook } from '@univerjs/sheets-ui';
+import { IEditorBridgeService, IFormulaEditorManagerService, SetCellEditVisibleOperation, useActiveWorkbook } from '@univerjs/sheets-ui';
import { KeyCode } from '@univerjs/ui';
import clsx from 'clsx';
import React, { useCallback, useLayoutEffect, useState } from 'react';
@@ -30,6 +30,7 @@ import styles from './index.module.less';
export const UniFormulaBar = () => {
const editorBridgeService = useDependency(IEditorBridgeService);
const univerInstanceService = useDependency(IUniverInstanceService);
+ const commandService = useDependency(ICommandService);
const visibleInfo = useObservable(editorBridgeService.visible$);
const focusedId = useObservable(univerInstanceService.focused$);
@@ -37,7 +38,7 @@ export const UniFormulaBar = () => {
const handleOpenWrite = useCallback(() => {
if (focusedId) {
- editorBridgeService.changeVisible({
+ commandService.executeCommand(SetCellEditVisibleOperation.id, {
visible: true,
eventType: DeviceInputEventType.PointerDown,
unitId: focusedId,
@@ -74,6 +75,7 @@ export function FormulaBar() {
const editorBridgeService = useDependency(IEditorBridgeService);
const themeService = useDependency(ThemeService);
const progressBarColor = themeService.getCurrentTheme().primaryColor;
+ const commandService = useDependency(ICommandService);
const [disable, setDisable] = useState<boolean>(false);
const univerInstanceService = useDependency(IUniverInstanceService);
const selectionManager = useDependency(SheetsSelectionsService);
@@ -179,7 +181,7 @@ export function FormulaBar() {
function handleCloseBtnClick() {
const visibleState = editorBridgeService.isVisible();
if (visibleState.visible) {
- editorBridgeService.changeVisible({
+ commandService.executeCommand(SetCellEditVisibleOperation.id, {
visible: false,
eventType: DeviceInputEventType.Keyboard,
keycode: KeyCode.ESC,
@@ -192,7 +194,7 @@ export function FormulaBar() {
function handleConfirmBtnClick() {
const visibleState = editorBridgeService.isVisible();
if (visibleState.visible) {
- editorBridgeService.changeVisible({
+ commandService.executeCommand(SetCellEditVisibleOperation.id, {
visible: false,
eventType: DeviceInputEventType.PointerDown,
unitId: currentWorkbook?.getUnitId() ?? '',
diff --git a/packages/docs-ui/src/basics/paragraph.ts b/packages/docs-ui/src/basics/paragraph.ts
index dac5783c0e..cf86b919bf 100644
--- a/packages/docs-ui/src/basics/paragraph.ts
+++ b/packages/docs-ui/src/basics/paragraph.ts
@@ -14,25 +14,31 @@
* limitations under the License.
*/
-import type { ICustomDecoration, ICustomRange, ICustomTable, IParagraph, ITextRun, ITextStyle, Nullable } from '@univerjs/core';
+import type { ICustomDecoration, ICustomRange, ICustomTable, IDocumentBody, IParagraph, ITextRun, ITextStyle, Nullable } from '@univerjs/core';
export function hasParagraphInTable(paragraph: IParagraph, tables: ICustomTable[]) {
return tables.some((table) => paragraph.startIndex > table.startIndex && paragraph.startIndex < table.endIndex);
}
export function getTextRunAtPosition(
- textRuns: ITextRun[],
+ body: IDocumentBody,
position: number,
defaultStyle: ITextStyle,
cacheStyle: Nullable<ITextStyle>,
isCellEditor?: boolean
): ITextRun {
+ const { textRuns = [], dataStream } = body;
+ const isFormula = isCellEditor && dataStream.startsWith('=');
const retTextRun: ITextRun = {
st: 0,
ed: 0,
ts: isCellEditor ? {} : defaultStyle,
};
+ if (isFormula) {
+ return retTextRun;
+ }
+
for (let i = textRuns.length - 1; i >= 0; i--) {
const textRun = textRuns[i];
const { st, ed } = textRun;
diff --git a/packages/docs-ui/src/commands/commands/break-line.command.ts b/packages/docs-ui/src/commands/commands/break-line.command.ts
index ff86890ea3..9b8f789c50 100644
--- a/packages/docs-ui/src/commands/commands/break-line.command.ts
+++ b/packages/docs-ui/src/commands/commands/break-line.command.ts
@@ -102,7 +102,7 @@ export const BreakLineCommand: ICommand = {
const defaultTextStyle = docMenuStyleService.getDefaultStyle();
const styleCache = docMenuStyleService.getStyleCache();
- const curTextRun = getTextRunAtPosition(body.textRuns ?? [], endOffset, defaultTextStyle, styleCache);
+ const curTextRun = getTextRunAtPosition(body, endOffset, defaultTextStyle, styleCache);
const insertBody: IDocumentBody = {
dataStream: DataStreamTreeTokenType.PARAGRAPH,
diff --git a/packages/docs-ui/src/commands/commands/ime-input.command.ts b/packages/docs-ui/src/commands/commands/ime-input.command.ts
index a7a96c2f18..3b43e8129d 100644
--- a/packages/docs-ui/src/commands/commands/ime-input.command.ts
+++ b/packages/docs-ui/src/commands/commands/ime-input.command.ts
@@ -16,9 +16,10 @@
import type { DocumentDataModel, ICommand, ICommandInfo } from '@univerjs/core';
import type { IRichTextEditingMutationParams } from '@univerjs/docs';
+import type { ITextRangeWithStyle } from '@univerjs/engine-render';
import { BuildTextUtils, CommandType, ICommandService, IUniverInstanceService, JSONX, SHEET_EDITOR_UNITS, TextX, TextXActionType, UniverInstanceType } from '@univerjs/core';
import { RichTextEditingMutation } from '@univerjs/docs';
-import { IRenderManagerService, type ITextRangeWithStyle } from '@univerjs/engine-render';
+import { IRenderManagerService } from '@univerjs/engine-render';
import { getCustomDecorationAtPosition, getCustomRangeAtPosition, getTextRunAtPosition } from '../../basics/paragraph';
import { DocIMEInputManagerService } from '../../services/doc-ime-input-manager.service';
import { DocMenuStyleService } from '../../services/doc-menu-style.service';
@@ -92,7 +93,7 @@ export const IMEInputCommand: ICommand<IIMEInputCommandParams> = {
const styleCache = docMenuStyleService.getStyleCache();
const curCustomRange = getCustomRangeAtPosition(body.customRanges ?? [], startOffset + oldTextLen, SHEET_EDITOR_UNITS.includes(unitId));
const curTextRun = getTextRunAtPosition(
- body.textRuns ?? [],
+ body,
isCompositionStart ? endOffset : startOffset + oldTextLen,
defaultTextStyle,
styleCache,
diff --git a/packages/docs-ui/src/commands/commands/table/doc-table-create.command.ts b/packages/docs-ui/src/commands/commands/table/doc-table-create.command.ts
index 8fc7fee7de..d851ee1d94 100644
--- a/packages/docs-ui/src/commands/commands/table/doc-table-create.command.ts
+++ b/packages/docs-ui/src/commands/commands/table/doc-table-create.command.ts
@@ -126,7 +126,7 @@ export const CreateDocTableCommand: ICommand<ICreateDocTableCommandParams> = {
const defaultTextStyle = docMenuStyleService.getDefaultStyle();
const styleCache = docMenuStyleService.getStyleCache();
const curTextRun = getTextRunAtPosition(
- body.textRuns ?? [],
+ body,
startOffset,
defaultTextStyle,
styleCache
diff --git a/packages/docs-ui/src/controllers/render-controllers/doc-input.controller.ts b/packages/docs-ui/src/controllers/render-controllers/doc-input.controller.ts
index e818e0231d..c2b2ad1ffc 100644
--- a/packages/docs-ui/src/controllers/render-controllers/doc-input.controller.ts
+++ b/packages/docs-ui/src/controllers/render-controllers/doc-input.controller.ts
@@ -71,13 +71,13 @@ export class DocInputController extends Disposable implements IRenderModule {
const { segmentId } = activeRange;
const docDataModel = this._context.unit;
- const originBody = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
+ const originBody = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()!;
// Insert content's style should follow the text style of the current position.
const defaultTextStyle = this._docMenuStyleService.getDefaultStyle();
const cacheStyle = this._docMenuStyleService.getStyleCache();
const curCustomRange = getCustomRangeAtPosition(originBody?.customRanges ?? [], activeRange.endOffset, SHEET_EDITOR_UNITS.includes(unitId));
- const curTextRun = getTextRunAtPosition(originBody?.textRuns ?? [], activeRange.endOffset, defaultTextStyle, cacheStyle, SHEET_EDITOR_UNITS.includes(unitId));
+ const curTextRun = getTextRunAtPosition(originBody, activeRange.endOffset, defaultTextStyle, cacheStyle, SHEET_EDITOR_UNITS.includes(unitId));
const curCustomDecorations = getCustomDecorationAtPosition(originBody?.customDecorations ?? [], activeRange.endOffset);
await this._commandService.executeCommand(InsertCommand.id, {
diff --git a/packages/docs-ui/src/services/editor/editor-manager.service.ts b/packages/docs-ui/src/services/editor/editor-manager.service.ts
index b17f6e13a2..0490f20854 100644
--- a/packages/docs-ui/src/services/editor/editor-manager.service.ts
+++ b/packages/docs-ui/src/services/editor/editor-manager.service.ts
@@ -149,6 +149,9 @@ export class EditorService extends Disposable implements IEditorService, IDispos
}
focus(editorUnitId: string) {
+ if (editorUnitId === this._focusEditorUnitId) {
+ return;
+ }
if (this._focusEditorUnitId) {
this.blur();
}
diff --git a/packages/sheets-data-validation-ui/src/views/components/list-dropdown/index.tsx b/packages/sheets-data-validation-ui/src/views/components/list-dropdown/index.tsx
index 006d4e36d3..5b498b702c 100644
--- a/packages/sheets-data-validation-ui/src/views/components/list-dropdown/index.tsx
+++ b/packages/sheets-data-validation-ui/src/views/components/list-dropdown/index.tsx
@@ -232,11 +232,11 @@ export function ListDropDown(props: IDropdownComponentProps) {
};
if (editorBridgeService.isVisible()) {
- editorBridgeService.changeVisible({
+ commandService.executeCommand(SetCellEditVisibleOperation.id, {
visible: false,
- keycode: KeyCode.ESC,
eventType: DeviceInputEventType.Keyboard,
unitId,
+ keycode: KeyCode.ESC,
});
}
setLocalValue(str);
diff --git a/packages/sheets-formula-ui/src/commands/operations/insert-function.operation.ts b/packages/sheets-formula-ui/src/commands/operations/insert-function.operation.ts
index b580718be2..d8b98e4a96 100644
--- a/packages/sheets-formula-ui/src/commands/operations/insert-function.operation.ts
+++ b/packages/sheets-formula-ui/src/commands/operations/insert-function.operation.ts
@@ -15,6 +15,7 @@
*/
import type { IAccessor, ICellData, ICommand, IRange, Nullable, ObjectMatrix } from '@univerjs/core';
+import type { IInsertFunction } from '@univerjs/sheets-formula';
import {
CellValueType,
CommandType,
@@ -36,8 +37,8 @@ import {
SetSelectionsOperation,
SheetsSelectionsService,
} from '@univerjs/sheets';
-import { type IInsertFunction, InsertFunctionCommand } from '@univerjs/sheets-formula';
-import { IEditorBridgeService } from '@univerjs/sheets-ui';
+import { InsertFunctionCommand } from '@univerjs/sheets-formula';
+import { IEditorBridgeService, SetCellEditVisibleOperation } from '@univerjs/sheets-ui';
export interface IInsertFunctionOperationParams {
/**
@@ -215,7 +216,7 @@ export const InsertFunctionOperation: ICommand = {
await commandService.executeCommand(SetSelectionsOperation.id, setSelectionParams);
const editor = editorService.getEditor(DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
const formulaEditor = editorService.getEditor(DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);
- editorBridgeService.changeVisible({
+ commandService.syncExecuteCommand(SetCellEditVisibleOperation.id, {
visible: true,
unitId,
eventType: DeviceInputEventType.Dblclick,
diff --git a/packages/sheets-formula-ui/src/views/more-functions/MoreFunctions.tsx b/packages/sheets-formula-ui/src/views/more-functions/MoreFunctions.tsx
index f34c5bba85..2176be5e34 100644
--- a/packages/sheets-formula-ui/src/views/more-functions/MoreFunctions.tsx
+++ b/packages/sheets-formula-ui/src/views/more-functions/MoreFunctions.tsx
@@ -15,12 +15,12 @@
*/
import type { IFunctionInfo } from '@univerjs/engine-formula';
-import { DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, IUniverInstanceService, LocaleService, useDependency } from '@univerjs/core';
+import { DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, ICommandService, IUniverInstanceService, LocaleService, useDependency } from '@univerjs/core';
import { Button } from '@univerjs/design';
import { IEditorService } from '@univerjs/docs-ui';
import { DeviceInputEventType } from '@univerjs/engine-render';
import { getSheetCommandTarget } from '@univerjs/sheets';
-import { IEditorBridgeService, useActiveWorkbook } from '@univerjs/sheets-ui';
+import { IEditorBridgeService, SetCellEditVisibleOperation, useActiveWorkbook } from '@univerjs/sheets-ui';
import React, { useState } from 'react';
import styles from './index.module.less';
import { InputParams } from './input-params/InputParams';
@@ -36,6 +36,7 @@ export function MoreFunctions() {
const localeService = useDependency(LocaleService);
const editorService = useDependency(IEditorService);
const univerInstanceService = useDependency(IUniverInstanceService);
+ const commandService = useDependency(ICommandService);
function handleClickNextPrev() {
if (selectFunction) {
@@ -49,7 +50,7 @@ export function MoreFunctions() {
function handleConfirm() {
const sheetTarget = getSheetCommandTarget(univerInstanceService);
if (!sheetTarget) return;
- editorBridgeService.changeVisible({
+ commandService.executeCommand(SetCellEditVisibleOperation.id, {
visible: true,
unitId: sheetTarget.unitId,
eventType: DeviceInputEventType.Dblclick,
diff --git a/packages/sheets-ui/src/controllers/auto-fill.controller.ts b/packages/sheets-ui/src/controllers/auto-fill.controller.ts
index 90474d3749..d056402b84 100644
--- a/packages/sheets-ui/src/controllers/auto-fill.controller.ts
+++ b/packages/sheets-ui/src/controllers/auto-fill.controller.ts
@@ -231,11 +231,14 @@ export class AutoFillController extends Disposable {
disposableCollection.add(controlSelection.fillControl.onPointerDown$.subscribeEvent(() => {
const visibleState = this._editorBridgeService.isVisible();
if (visibleState.visible) {
- this._editorBridgeService.changeVisible({
- visible: false,
- eventType: DeviceInputEventType.PointerDown,
- unitId: currentRenderer.unitId,
- });
+ this._commandService.syncExecuteCommand(
+ SetCellEditVisibleOperation.id,
+ {
+ visible: false,
+ eventType: DeviceInputEventType.PointerDown,
+ unitId: currentRenderer.unitId,
+ }
+ );
}
}));
});
diff --git a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts b/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts
index e52b88c847..99ca0fa932 100644
--- a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts
+++ b/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts
@@ -60,7 +60,7 @@ import { KeyCode } from '@univerjs/ui';
import { distinctUntilChanged, filter } from 'rxjs';
import { getEditorObject } from '../../basics/editor/get-editor-object';
import { MoveSelectionCommand, MoveSelectionEnterAndTabCommand } from '../../commands/commands/set-selection.command';
-import { SetCellEditVisibleArrowOperation, SetCellEditVisibleWithF2Operation } from '../../commands/operations/cell-edit.operation';
+import { SetCellEditVisibleArrowOperation, SetCellEditVisibleOperation, SetCellEditVisibleWithF2Operation } from '../../commands/operations/cell-edit.operation';
import { ScrollToRangeOperation } from '../../commands/operations/scroll-to-range.operation';
import { IEditorBridgeService } from '../../services/editor-bridge.service';
import { ICellEditorManagerService } from '../../services/editor/cell-editor-manager.service';
@@ -176,7 +176,7 @@ export class EditingRenderController extends Disposable implements IRenderModule
this._editorBridgeService.visible$
.pipe(distinctUntilChanged((prev, curr) => prev.visible === curr.visible))
.subscribe((param) => {
- if ((param.unitId === DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY || param.unitId === this._context.unitId) && param.visible) {
+ if ((param.unitId === DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY || param.unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY || param.unitId === this._context.unitId) && param.visible) {
this._isUnitEditing = true;
this._handleEditorVisible(param);
} else if (this._isUnitEditing) {
@@ -342,7 +342,7 @@ export class EditingRenderController extends Disposable implements IRenderModule
// TODO@Jocs: After we merging editor related controllers, this seems verbose.
// We can directly call SetRangeValues here.
- this._editorBridgeService.changeVisible(params);
+ this._commandService.syncExecuteCommand(SetCellEditVisibleOperation.id, params);
}
if (command.id === SetCellEditVisibleWithF2Operation.id) {
diff --git a/packages/sheets-ui/src/controllers/editor/formula-editor.controller.ts b/packages/sheets-ui/src/controllers/editor/formula-editor.controller.ts
index e36593370f..844e9e3234 100644
--- a/packages/sheets-ui/src/controllers/editor/formula-editor.controller.ts
+++ b/packages/sheets-ui/src/controllers/editor/formula-editor.controller.ts
@@ -77,8 +77,10 @@ export class FormulaEditorController extends RxDisposable {
this.disposeWithMe(this._editorService.focus$.subscribe(() => {
const focusUnitId = this._editorService.getFocusEditor()?.getEditorId();
- if (focusUnitId === DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) {
+ if (focusUnitId !== DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) {
this._contextService.setContextValue(FOCUSING_FX_BAR_EDITOR, false);
+ } else {
+ this._contextService.setContextValue(FOCUSING_FX_BAR_EDITOR, true);
}
}));
}
diff --git a/packages/sheets-ui/src/controllers/render-controllers/header-resize.render-controller.ts b/packages/sheets-ui/src/controllers/render-controllers/header-resize.render-controller.ts
index 8b6dc0aac4..0bb9017537 100644
--- a/packages/sheets-ui/src/controllers/render-controllers/header-resize.render-controller.ts
+++ b/packages/sheets-ui/src/controllers/render-controllers/header-resize.render-controller.ts
@@ -371,12 +371,6 @@ export class HeaderResizeRenderController extends Disposable implements IRenderM
scene.addObject(this._resizeHelperShape, SHEET_COMPONENT_HEADER_LAYER_INDEX);
scene.disableObjectsEvent();
- // TODO: do it in another way
- // this._editorBridgeService.changeVisible({
- // visible: false,
- // eventType: DeviceInputEventType.PointerDown,
- // });
-
this._scenePointerMoveSub = scene.onPointerMove$.subscribeEvent((moveEvt: IPointerEvent | IMouseEvent) => {
const relativeCoords = scene.getCoordRelativeToViewport(
Vector2.FromArray([this._startOffsetX, this._startOffsetY])
diff --git a/packages/sheets-ui/src/services/editor-bridge.service.ts b/packages/sheets-ui/src/services/editor-bridge.service.ts
index 69433a1735..0770cb5199 100644
--- a/packages/sheets-ui/src/services/editor-bridge.service.ts
+++ b/packages/sheets-ui/src/services/editor-bridge.service.ts
@@ -94,6 +94,9 @@ export interface IEditorBridgeService {
getEditLocation(): Readonly<Nullable<ICellEditorState>>;
// Gets the DocumentDataModel of the latest table cell based on the latest cell contents
getLatestEditCellState(): Readonly<Nullable<IEditorBridgeServiceParam>>;
+ /**
+ * @deprecated do not use it directly, use command SetCellEditVisibleOperation as instead.
+ */
changeVisible(param: IEditorBridgeServiceVisibleParam): void;
changeEditorDirty(dirtyStatus: boolean): void;
getEditorDirty(): boolean;
diff --git a/packages/sheets-ui/src/views/editor-container/EditorContainer.tsx b/packages/sheets-ui/src/views/editor-container/EditorContainer.tsx
index 1e1fa8476c..2c49339b36 100644
--- a/packages/sheets-ui/src/views/editor-container/EditorContainer.tsx
+++ b/packages/sheets-ui/src/views/editor-container/EditorContainer.tsx
@@ -20,7 +20,7 @@ import { IEditorService } from '@univerjs/docs-ui';
import { DeviceInputEventType } from '@univerjs/engine-render';
import { ComponentManager, DISABLE_AUTO_FOCUS_KEY, MetaKeys, useEvent, useObservable, useSidebarClick } from '@univerjs/ui';
import React, { useEffect, useRef, useState } from 'react';
-import { SetCellEditVisibleArrowOperation } from '../../commands/operations/cell-edit.operation';
+import { SetCellEditVisibleArrowOperation, SetCellEditVisibleOperation } from '../../commands/operations/cell-edit.operation';
import { EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY } from '../../common/keys';
import { IEditorBridgeService } from '../../services/editor-bridge.service';
@@ -116,10 +116,10 @@ export const EditorContainer: React.FC<ICellIEditorProps> = () => {
const handleClickSideBar = useEvent(() => {
if (editorBridgeService.isVisible().visible) {
- editorBridgeService.changeVisible({
+ commandService.executeCommand(SetCellEditVisibleOperation.id, {
visible: false,
eventType: DeviceInputEventType.PointerUp,
- unitId: editState!.unitId,
+ unitId: editState?.unitId,
});
}
});
diff --git a/packages/sheets-ui/src/views/editor-container/hooks.ts b/packages/sheets-ui/src/views/editor-container/hooks.ts
index 37ecbb871e..b7a20691d9 100644
--- a/packages/sheets-ui/src/views/editor-container/hooks.ts
+++ b/packages/sheets-ui/src/views/editor-container/hooks.ts
@@ -14,15 +14,17 @@
* limitations under the License.
*/
-import { IUniverInstanceService, useDependency, useObservable } from '@univerjs/core';
+import { ICommandService, useDependency, useObservable } from '@univerjs/core';
import { DocSelectionRenderService } from '@univerjs/docs-ui';
import { DeviceInputEventType, IRenderManagerService } from '@univerjs/engine-render';
import { KeyCode } from '@univerjs/ui';
import { useMemo } from 'react';
+import { SetCellEditVisibleOperation } from '../../commands/operations/cell-edit.operation';
import { IEditorBridgeService } from '../../services/editor-bridge.service';
export function useKeyEventConfig(isRefSelecting: React.MutableRefObject<0 | 1 | 2>, unitId: string) {
const editorBridgeService = useDependency(IEditorBridgeService);
+ const commandService = useDependency(ICommandService);
const keyCodeConfig = useMemo(() => ({
keyCodes: [
@@ -33,7 +35,7 @@ export function useKeyEventConfig(isRefSelecting: React.MutableRefObject<0 | 1 |
handler: (keycode: KeyCode) => {
if (keycode === KeyCode.ENTER || keycode === KeyCode.ESC || keycode === KeyCode.TAB) {
editorBridgeService.disableForceKeepVisible();
- editorBridgeService.changeVisible({
+ commandService.executeCommand(SetCellEditVisibleOperation.id, {
visible: false,
eventType: DeviceInputEventType.Keyboard,
keycode,
@@ -41,23 +43,16 @@ export function useKeyEventConfig(isRefSelecting: React.MutableRefObject<0 | 1 |
});
}
},
- }), [editorBridgeService, unitId]);
+ }), [commandService, editorBridgeService, unitId]);
return keyCodeConfig;
}
export function useIsFocusing(editorId: string) {
- const univerInstanceService = useDependency(IUniverInstanceService);
const renderManagerService = useDependency(IRenderManagerService);
const docSelectionRenderService = renderManagerService.getRenderById(editorId)?.with(DocSelectionRenderService);
useObservable(docSelectionRenderService?.onBlur$);
useObservable(docSelectionRenderService?.onFocus$);
- // useEffect(() => {
- // if (docSelectionRenderService?.isFocusing) {
- // univerInstanceService.focusUnit(editorId);
- // }
- // }, [docSelectionRenderService?.isFocusing, editorId, univerInstanceService]);
-
return docSelectionRenderService?.isFocusing;
}
diff --git a/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx b/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx
index 69ce1bc1f6..e16f422928 100644
--- a/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx
+++ b/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx
@@ -52,7 +52,7 @@ export function FormulaBar() {
const selectionManager = useDependency(SheetsSelectionsService);
const permissionService = useDependency(IPermissionService);
const rangeProtectionCache = useDependency(RangeProtectionCache);
-
+ const commandService = useDependency(ICommandService);
const [disableInfo, setDisableInfo] = useState<{ editDisable: boolean; viewDisable: boolean }>({
editDisable: false,
viewDisable: false,
@@ -181,7 +181,7 @@ export function FormulaBar() {
function handleCloseBtnClick() {
const visibleState = editorBridgeService.isVisible();
if (visibleState.visible) {
- editorBridgeService.changeVisible({
+ commandService.executeCommand(SetCellEditVisibleOperation.id, {
visible: false,
eventType: DeviceInputEventType.Keyboard,
keycode: KeyCode.ESC,
@@ -194,7 +194,7 @@ export function FormulaBar() {
function handleConfirmBtnClick() {
const visibleState = editorBridgeService.isVisible();
if (visibleState.visible) {
- editorBridgeService.changeVisible({
+ commandService.executeCommand(SetCellEditVisibleOperation.id, {
visible: false,
eventType: DeviceInputEventType.PointerDown,
unitId: currentWorkbook?.getUnitId() ?? '',
@@ -210,7 +210,7 @@ export function FormulaBar() {
const { viewDisable, editDisable } = disableInfo;
const disabled = editDisable || imageDisable;
const shouldSkipFocus = useRef(false);
- const commandService = useDependency(ICommandService);
+
const unitId = currentWorkbook?.getUnitId() ?? '';
const handlePointerDown = () => {
diff --git a/packages/slides-ui/src/controllers/slide-editor-bridge.render-controller.ts b/packages/slides-ui/src/controllers/slide-editor-bridge.render-controller.ts
index 82a67a68d3..7343fd78c2 100644
--- a/packages/slides-ui/src/controllers/slide-editor-bridge.render-controller.ts
+++ b/packages/slides-ui/src/controllers/slide-editor-bridge.render-controller.ts
@@ -15,15 +15,15 @@
*/
import type { IDisposable, Nullable, SlideDataModel, UnitModel } from '@univerjs/core';
-import { DisposableCollection, ICommandService, IUniverInstanceService, RxDisposable, UniverInstanceType } from '@univerjs/core';
-
import type { BaseObject, IRenderContext, IRenderModule, RichText, Scene, Slide } from '@univerjs/engine-render';
+
+import type { ISetEditorInfo } from '../services/slide-editor-bridge.service';
+import type { ISlideRichTextProps } from '../type';
+import { DisposableCollection, ICommandService, IUniverInstanceService, RxDisposable, UniverInstanceType } from '@univerjs/core';
import { DeviceInputEventType, ObjectType } from '@univerjs/engine-render';
import { Subject } from 'rxjs';
import { UpdateSlideElementOperation } from '../commands/operations/update-element.operation';
-import type { ISetEditorInfo } from '../services/slide-editor-bridge.service';
import { ISlideEditorBridgeService } from '../services/slide-editor-bridge.service';
-import type { ISlideRichTextProps } from '../type';
// interface ICanvasOffset {
// left: number;