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: #911 using the undo shortcut after you clear the content goes into edit mode (#979)
Gpound.liua72c9948e4c7
diff --git a/examples/src/plugins/local-save/controller/record.controller.ts b/examples/src/plugins/local-save/controller/record.controller.tsindex dac6ff42c4..2cd41e06bb 100644--- a/examples/src/plugins/local-save/controller/record.controller.ts+++ b/examples/src/plugins/local-save/controller/record.controller.ts@@ -53,7 +53,7 @@ export class RecordController {type ParamsString = string & {};const result: Array<[SecondsString, CommandString, TypeString, ParamsString]> = [];const startTime = performance.now();- const disposable = this._commandService.onCommandExecuted((commandInfo) => {+ const disposable = this._commandService.beforeCommandExecuted((commandInfo) => {try {result.push([String((performance.now() - startTime) / 1000),diff --git a/packages/sheets-numfmt/src/components/more-numfmt-type/MoreNumfmtType.tsx b/packages/sheets-numfmt/src/components/more-numfmt-type/MoreNumfmtType.tsxindex 835b97b99e..6a8e71b748 100644--- a/packages/sheets-numfmt/src/components/more-numfmt-type/MoreNumfmtType.tsx+++ b/packages/sheets-numfmt/src/components/more-numfmt-type/MoreNumfmtType.tsx@@ -18,9 +18,10 @@ import './index.less';import { ICommandService, LocaleService, Range } from '@univerjs/core';import numfmt from '@univerjs/engine-numfmt';+import { ITextSelectionRenderManager } from '@univerjs/engine-render';import type { FormatType } from '@univerjs/sheets';import { SelectionManagerService } from '@univerjs/sheets';-import { useDependency } from '@wendellhu/redi/react-bindings';+import { useDependency, useInjector } from '@wendellhu/redi/react-bindings';import React from 'react';import { MENU_OPTIONS } from '../../base/const/MENU-OPTIONS';@@ -37,6 +38,7 @@ export const MoreNumfmtType = (props: { value?: string }) => {export const Options = () => {const commandService = useDependency(ICommandService);const localeService = useDependency(LocaleService);+ const injector = useInjector();const selectionManagerService = useDependency(SelectionManagerService);const setNumfmt = (pattern: string | null) => {@@ -44,6 +46,7 @@ export const Options = () => {if (!selection) {return;}+ const textSelectionRenderManager = injector.get(ITextSelectionRenderManager);const range = selection.range;const values: Array<{ row: number; col: number; pattern?: string; type?: FormatType }> = [];Range.foreach(range, (row, col) => {@@ -54,6 +57,7 @@ export const Options = () => {}});commandService.executeCommand(SetNumfmtCommand.id, { values });+ textSelectionRenderManager.focus();};const handleOnclick = (index: number) => {if (index === 0) {diff --git a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsxindex f7c1f025c4..a50e931919 100644--- a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx+++ b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx@@ -16,6 +16,7 @@import type { ICommandInfo } from '@univerjs/core';import { BooleanNumber, ICommandService, IUniverInstanceService, LocaleService } from '@univerjs/core';+import { ITextSelectionRenderManager } from '@univerjs/engine-render';import {InsertSheetMutation,RemoveSheetMutation,@@ -29,7 +30,7 @@ import {SetWorksheetOrderMutation,} from '@univerjs/sheets';import { IConfirmService } from '@univerjs/ui';-import { useDependency } from '@wendellhu/redi/react-bindings';+import { useDependency, useInjector } from '@wendellhu/redi/react-bindings';import React, { useEffect, useRef, useState } from 'react';import { ISheetBarService } from '../../../services/sheet-bar/sheet-bar.service';@@ -53,6 +54,7 @@ export function SheetBarTabs() {const sheetBarService = useDependency(ISheetBarService);const localeService = useDependency(LocaleService);const confirmService = useDependency(IConfirmService);+ const injector = useInjector();const workbook = univerInstanceService.getCurrentUniverSheetInstance();@@ -103,6 +105,13 @@ export function SheetBarTabs() {subUnitId,unitId: workbook.getUnitId(),});+ // The 'onChangeTab' event occurs during the 'pointerDown' event.+ // The triggering time is too early.+ // Settimeout is required to delay resetting the focus.+ setTimeout(() => {+ const textSelectionRenderManager = injector.get(ITextSelectionRenderManager);+ textSelectionRenderManager.focus();+ }, 0);},onScroll: (state: IScrollState) => {sheetBarService.setScroll(state);diff --git a/packages/ui/src/views/components/context-menu/ContextMenu.tsx b/packages/ui/src/views/components/context-menu/ContextMenu.tsxindex 2711a4ac02..92c1f528e5 100644--- a/packages/ui/src/views/components/context-menu/ContextMenu.tsx+++ b/packages/ui/src/views/components/context-menu/ContextMenu.tsx@@ -17,7 +17,8 @@import { ICommandService } from '@univerjs/core';import { Popup } from '@univerjs/design';import type { IMouseEvent } from '@univerjs/engine-render';-import { useDependency } from '@wendellhu/redi/react-bindings';+import { ITextSelectionRenderManager } from '@univerjs/engine-render';+import { useDependency, useInjector } from '@wendellhu/redi/react-bindings';import React, { useEffect, useState } from 'react';import { Menu } from '../../../components/menu/Menu';@@ -32,6 +33,7 @@ export function ContextMenu() {const contextMenuService = useDependency(IContextMenuService);const commandService = useDependency(ICommandService);+ const injector = useInjector();useEffect(() => {const disposables = contextMenuService.registerContextMenuHandler({@@ -66,6 +68,8 @@ export function ContextMenu() {onOptionSelect={(params) => {const { label: commandId, value } = params;commandService && commandService.executeCommand(commandId as string, { value });+ const textSelectionRenderManager = injector.get(ITextSelectionRenderManager);+ textSelectionRenderManager.focus();setVisible(false);}}/>diff --git a/packages/ui/src/views/components/doc-bars/ToolbarItem.tsx b/packages/ui/src/views/components/doc-bars/ToolbarItem.tsxindex 58b4b3c695..a26b797649 100644--- a/packages/ui/src/views/components/doc-bars/ToolbarItem.tsx+++ b/packages/ui/src/views/components/doc-bars/ToolbarItem.tsx@@ -16,8 +16,9 @@import { ICommandService, LocaleService } from '@univerjs/core';import { Dropdown, Tooltip } from '@univerjs/design';+import { ITextSelectionRenderManager } from '@univerjs/engine-render';import { MoreDownSingle } from '@univerjs/icons';-import { useDependency } from '@wendellhu/redi/react-bindings';+import { useDependency, useInjector } from '@wendellhu/redi/react-bindings';import type { Ref } from 'react';import React, { forwardRef, useEffect, useState } from 'react';import type { Subscription } from 'rxjs';@@ -35,13 +36,19 @@ import styles from './index.module.less';export const ToolbarItem = forwardRef((props: IDisplayMenuItem<IMenuItem>, ref: Ref<any>) => {const localeService = useDependency(LocaleService);const commandService = useDependency(ICommandService);-+ const injector = useInjector();// eslint-disable-next-line @typescript-eslint/no-explicit-anyconst [value, setValue] = useState<any>();const [disabled, setDisabled] = useState(false);const [activated, setActivated] = useState(false);const [hidden, setHidden] = useState(false);+ const handleCommandExecuted = (commandId: string, params?: Record<string, any>) => {+ commandService.executeCommand(commandId, params);+ const textSelectionRenderManager = injector.get(ITextSelectionRenderManager);+ textSelectionRenderManager.focus();+ };+useEffect(() => {const subscriptions: Subscription[] = [];@@ -105,18 +112,18 @@ export const ToolbarItem = forwardRef((props: IDisplayMenuItem<IMenuItem>, ref:commandId = option.id;}- commandService.executeCommand(commandId, value);+ handleCommandExecuted(commandId, value);}function handleChange(value: string | number) {const commandId = id;- commandService.executeCommand(commandId, { value });+ handleCommandExecuted(commandId, { value });}function handleClick() {if (menuType === MenuItemType.BUTTON_SELECTOR) {const commandId = id;- commandService.executeCommand(commandId, { value });+ handleCommandExecuted(commandId, { value });}}@@ -166,8 +173,8 @@ export const ToolbarItem = forwardRef((props: IDisplayMenuItem<IMenuItem>, ref:className={styles.toolbarItemTextButton}active={activated}disabled={disabled}- onClick={() => commandService.executeCommand(props.id)}- onDoubleClick={() => props.subId && commandService.executeCommand(props.subId)}+ onClick={() => handleCommandExecuted(props.id)}+ onDoubleClick={() => props.subId && handleCommandExecuted(props.subId)}>{isCustomComponent ? (<CustomLabel title={title!} value={value} label={label} />