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): allow inline format shortcuts to fire inside cell editor (#6851)

Shiyun Hua4b98f87b66db
diff --git a/packages/sheets-ui/src/controllers/shortcuts/style.shortcut.ts b/packages/sheets-ui/src/controllers/shortcuts/style.shortcut.ts
index 5d4e2e4432..c5f403bf28 100644
--- a/packages/sheets-ui/src/controllers/shortcuts/style.shortcut.ts
+++ b/packages/sheets-ui/src/controllers/shortcuts/style.shortcut.ts
@@ -23,13 +23,13 @@ import {
SetRangeStrickThroughCommand,
SetRangeUnderlineCommand,
} from '../../commands/commands/inline-format.command';
-import { whenSheetEditorFocused } from './utils';
+import { whenSheetFocusedInlineFormat } from './utils';
export const SetBoldShortcutItem: IShortcutItem = {
id: SetRangeBoldCommand.id,
description: 'shortcut.sheet.set-bold',
group: '4_sheet-edit',
- preconditions: (contextService) => whenSheetEditorFocused(contextService),
+ preconditions: (contextService) => whenSheetFocusedInlineFormat(contextService),
binding: KeyCode.B | MetaKeys.CTRL_COMMAND,
};
@@ -37,7 +37,7 @@ export const SetItalicShortcutItem: IShortcutItem = {
id: SetRangeItalicCommand.id,
description: 'shortcut.sheet.set-italic',
group: '4_sheet-edit',
- preconditions: (contextService) => whenSheetEditorFocused(contextService),
+ preconditions: (contextService) => whenSheetFocusedInlineFormat(contextService),
binding: KeyCode.I | MetaKeys.CTRL_COMMAND,
};
@@ -45,7 +45,7 @@ export const SetUnderlineShortcutItem: IShortcutItem = {
id: SetRangeUnderlineCommand.id,
description: 'shortcut.sheet.set-underline',
group: '4_sheet-edit',
- preconditions: (contextService) => whenSheetEditorFocused(contextService),
+ preconditions: (contextService) => whenSheetFocusedInlineFormat(contextService),
binding: KeyCode.U | MetaKeys.CTRL_COMMAND,
};
@@ -53,6 +53,6 @@ export const SetStrikeThroughShortcutItem: IShortcutItem = {
id: SetRangeStrickThroughCommand.id,
description: 'shortcut.sheet.set-strike-through',
group: '4_sheet-edit',
- preconditions: (contextService) => whenSheetEditorFocused(contextService),
+ preconditions: (contextService) => whenSheetFocusedInlineFormat(contextService),
binding: KeyCode.X | MetaKeys.SHIFT | MetaKeys.CTRL_COMMAND,
};
diff --git a/packages/sheets-ui/src/controllers/shortcuts/utils.ts b/packages/sheets-ui/src/controllers/shortcuts/utils.ts
index 20e20af0de..ecfbfcac68 100644
--- a/packages/sheets-ui/src/controllers/shortcuts/utils.ts
+++ b/packages/sheets-ui/src/controllers/shortcuts/utils.ts
@@ -43,6 +43,21 @@ export function whenSheetEditorFocused(contextService: IContextService): boolean
);
}
+/**
+ * Requires the currently focused unit to be Workbook, regardless of whether the cell editor is activated.
+ * Used by inline-format shortcuts (bold/italic/underline/strikethrough) so they can also fire
+ * inside the cell editor — the corresponding command will route to the docs inline-format command
+ * when EDITOR_ACTIVATED is true.
+ * @param contextService
+ */
+export function whenSheetFocusedInlineFormat(contextService: IContextService): boolean {
+ return (
+ contextService.getContextValue(FOCUSING_SHEET) &&
+ contextService.getContextValue(FOCUSING_UNIVER_EDITOR) &&
+ !contextService.getContextValue(FOCUSING_COMMON_DRAWINGS)
+ );
+}
+
export function whenSheetEditorFocusedAndFxNotFocused(contextService: IContextService): boolean {
return (
contextService.getContextValue(FOCUSING_SHEET) &&