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(sheet): fix sheet paste command not working (#1226)

Wenzhao Hu0a2c944c933e
diff --git a/packages/sheets-ui/src/commands/commands/clipboard.command.ts b/packages/sheets-ui/src/commands/commands/clipboard.command.ts
index 608c4837c0..e1732ad2ee 100644
--- a/packages/sheets-ui/src/commands/commands/clipboard.command.ts
+++ b/packages/sheets-ui/src/commands/commands/clipboard.command.ts
@@ -19,7 +19,7 @@ import { CommandType, ICommandService, ILogService } from '@univerjs/core';
import { CopyCommand, CutCommand, IClipboardInterfaceService, PasteCommand } from '@univerjs/ui';
import type { IAccessor } from '@wendellhu/redi';
-import { whenSheetEditorFocused } from '../../controllers/shortcuts/utils';
+import { whenSheetFocused } from '../../controllers/shortcuts/utils';
import { ISheetClipboardService, PREDEFINED_HOOK_NAME } from '../../services/clipboard/clipboard.service';
export const SheetCopyCommand: IMultiCommand = {
@@ -28,7 +28,7 @@ export const SheetCopyCommand: IMultiCommand = {
type: CommandType.COMMAND,
multi: true,
priority: 1000,
- preconditions: whenSheetEditorFocused,
+ preconditions: whenSheetFocused,
handler: async (accessor) => {
const sheetClipboardService = accessor.get(ISheetClipboardService);
return sheetClipboardService.copy();
@@ -41,7 +41,7 @@ export const SheetCutCommand: IMultiCommand = {
type: CommandType.COMMAND,
multi: true,
priority: 1000,
- preconditions: whenSheetEditorFocused,
+ preconditions: whenSheetFocused,
handler: async (accessor) => {
const sheetClipboardService = accessor.get(ISheetClipboardService);
return sheetClipboardService.cut();
@@ -58,7 +58,7 @@ export const SheetPasteCommand: IMultiCommand = {
multi: true,
name: 'sheet.command.paste',
priority: 1000,
- preconditions: whenSheetEditorFocused,
+ preconditions: whenSheetFocused,
handler: async (accessor: IAccessor, params: ISheetPasteParams) => {
const logService = accessor.get(ILogService);
diff --git a/packages/sheets-ui/src/controllers/shortcuts/utils.ts b/packages/sheets-ui/src/controllers/shortcuts/utils.ts
index b2a8f060c9..370fad04fe 100644
--- a/packages/sheets-ui/src/controllers/shortcuts/utils.ts
+++ b/packages/sheets-ui/src/controllers/shortcuts/utils.ts
@@ -23,7 +23,9 @@ import {
FOCUSING_UNIVER_EDITOR,
} from '@univerjs/core';
-// TODO@wzhudev: some definition here is pretty ambiguous and not very consistent. Rename them.
+export function whenSheetFocused(contextService: IContextService) {
+ return contextService.getContextValue(FOCUSING_SHEET);
+}
/**
* Requires the currently focused unit to be Workbook and the sheet editor is focused but not activated.