Skip to content

Commit

Permalink
fix: fix sheet command preconditions (#1319)
Browse files Browse the repository at this point in the history
  • Loading branch information
wzhudev committed Feb 3, 2024
1 parent 4065ea8 commit 6e92c60
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions packages/sheets-ui/src/commands/commands/clipboard.command.ts
Expand Up @@ -14,18 +14,14 @@
* limitations under the License.
*/

import type { ICommand, IContextService, IMultiCommand } from '@univerjs/core';
import { CommandType, EDITOR_ACTIVATED, ICommandService, ILogService } from '@univerjs/core';
import type { ICommand, IMultiCommand } from '@univerjs/core';
import { CommandType, ICommandService, ILogService } from '@univerjs/core';
import { CopyCommand, CutCommand, IClipboardInterfaceService, PasteCommand } from '@univerjs/ui';
import type { IAccessor } from '@wendellhu/redi';

import { whenSheetEditorActivated, whenSheetEditorFocused } from '../../controllers/shortcuts/utils';
import { whenSheetFocused } from '../../controllers/shortcuts/utils';
import { ISheetClipboardService, PREDEFINED_HOOK_NAME } from '../../services/clipboard/clipboard.service';

function whenSheetEditorNotActivated(context: IContextService): boolean {
return whenSheetEditorFocused(context) && !context.getContextValue(EDITOR_ACTIVATED);
}

const SHEET_CLIPBOARD_PRIORITY = 998;

export const SheetCopyCommand: IMultiCommand = {
Expand All @@ -34,7 +30,7 @@ export const SheetCopyCommand: IMultiCommand = {
type: CommandType.COMMAND,
multi: true,
priority: SHEET_CLIPBOARD_PRIORITY,
preconditions: whenSheetEditorNotActivated,
preconditions: whenSheetFocused,
handler: async (accessor) => {
const sheetClipboardService = accessor.get(ISheetClipboardService);
return sheetClipboardService.copy();
Expand All @@ -47,7 +43,7 @@ export const SheetCutCommand: IMultiCommand = {
type: CommandType.COMMAND,
multi: true,
priority: SHEET_CLIPBOARD_PRIORITY,
preconditions: whenSheetEditorActivated,
preconditions: whenSheetFocused,
handler: async (accessor) => {
const sheetClipboardService = accessor.get(ISheetClipboardService);
return sheetClipboardService.cut();
Expand All @@ -64,7 +60,7 @@ export const SheetPasteCommand: IMultiCommand = {
multi: true,
name: 'sheet.command.paste',
priority: SHEET_CLIPBOARD_PRIORITY,
preconditions: whenSheetEditorNotActivated,
preconditions: whenSheetFocused,
handler: async (accessor: IAccessor, params: ISheetPasteParams) => {
const logService = accessor.get(ILogService);

Expand Down

0 comments on commit 6e92c60

Please sign in to comment.