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.

feat(sheets-ui): add Shift and Alt clear selection shortcuts (#5031)

ZhangWei8bcd0a3e0356
diff --git a/packages/sheets-ui/src/controllers/sheet-ui.controller.ts b/packages/sheets-ui/src/controllers/sheet-ui.controller.ts
index fa002879b4..daa3baec14 100644
--- a/packages/sheets-ui/src/controllers/sheet-ui.controller.ts
+++ b/packages/sheets-ui/src/controllers/sheet-ui.controller.ts
@@ -152,7 +152,7 @@ import {
SetStrikeThroughShortcutItem,
SetUnderlineShortcutItem,
} from './shortcuts/style.shortcut';
-import { ClearSelectionValueShortcutItem, ClearSelectionValueShortcutItemMac } from './shortcuts/value.shortcut';
+import { ClearSelectionValueShortcutItem, ClearSelectionValueShortcutItemMac, ShiftClearSelectionValueShortcutItem } from './shortcuts/value.shortcut';
import {
PreventDefaultResetZoomShortcutItem,
PreventDefaultZoomInShortcutItem,
@@ -331,6 +331,7 @@ export class SheetUIController extends Disposable {
// cell content editing shortcuts
ClearSelectionValueShortcutItem,
ClearSelectionValueShortcutItemMac,
+ ShiftClearSelectionValueShortcutItem,
...generateArrowSelectionShortCutItem(),
EditorCursorEnterShortcut,
StartEditWithF2Shortcut,
diff --git a/packages/sheets-ui/src/controllers/shortcuts/value.shortcut.ts b/packages/sheets-ui/src/controllers/shortcuts/value.shortcut.ts
index dcba6ef7c2..76e3e40220 100644
--- a/packages/sheets-ui/src/controllers/shortcuts/value.shortcut.ts
+++ b/packages/sheets-ui/src/controllers/shortcuts/value.shortcut.ts
@@ -16,7 +16,7 @@
import type { IShortcutItem } from '@univerjs/ui';
import { ClearSelectionContentCommand } from '@univerjs/sheets';
-import { KeyCode } from '@univerjs/ui';
+import { KeyCode, MetaKeys } from '@univerjs/ui';
import { whenSheetEditorFocused } from './utils';
@@ -34,3 +34,11 @@ export const ClearSelectionValueShortcutItemMac: IShortcutItem = {
preconditions: (contextService) => whenSheetEditorFocused(contextService),
mac: KeyCode.DELETE,
};
+
+export const ShiftClearSelectionValueShortcutItem: IShortcutItem = {
+ id: ClearSelectionContentCommand.id,
+ // when focusing on any other input tag do not trigger this shortcut
+ preconditions: (contextService) => whenSheetEditorFocused(contextService),
+ binding: MetaKeys.SHIFT + KeyCode.DELETE,
+ mac: MetaKeys.SHIFT + KeyCode.BACKSPACE,
+};