From 64e22a85376432613ee4e01c79e060ae7f021470 Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Wed, 12 Apr 2017 10:54:28 +0200 Subject: [PATCH] GH-22: Removed cut/cop/paste common commands. Signed-off-by: Akos Kitta --- src/application/common/commands-common.ts | 34 --------------------- src/editor/browser/editor-command.ts | 6 ++-- src/editor/browser/editor-module.ts | 37 ++++------------------- typings/monaco/index.d.ts | 19 ------------ 4 files changed, 9 insertions(+), 87 deletions(-) diff --git a/src/application/common/commands-common.ts b/src/application/common/commands-common.ts index 1505fa9649b99..01b7eb4e2b0c4 100644 --- a/src/application/common/commands-common.ts +++ b/src/application/common/commands-common.ts @@ -7,10 +7,6 @@ export namespace CommonCommands { export const EDIT_MENU_UNDO_GROUP = "1_undo/redo" export const EDIT_MENU_COPYPASTE_GROUP = "2_copy" - export const EDIT_CUT = monaco.editor.Handler.Cut; - export const EDIT_COPY = 'copy'; - export const EDIT_PASTE = monaco.editor.Handler.Paste; - export const EDIT_UNDO = monaco.editor.Handler.Undo; export const EDIT_REDO = monaco.editor.Handler.Redo; } @@ -30,24 +26,6 @@ export class CommonMenuContribution implements MenuContribution { CommonCommands.EDIT_MENU_UNDO_GROUP], { commandId: CommonCommands.EDIT_REDO }); - registry.registerMenuAction([ - MAIN_MENU_BAR, - CommonCommands.EDIT_MENU, - CommonCommands.EDIT_MENU_COPYPASTE_GROUP], { - commandId: CommonCommands.EDIT_CUT - }); - registry.registerMenuAction([ - MAIN_MENU_BAR, - CommonCommands.EDIT_MENU, - CommonCommands.EDIT_MENU_COPYPASTE_GROUP], { - commandId: CommonCommands.EDIT_COPY - }); - registry.registerMenuAction([ - MAIN_MENU_BAR, - CommonCommands.EDIT_MENU, - CommonCommands.EDIT_MENU_COPYPASTE_GROUP], { - commandId: CommonCommands.EDIT_PASTE - }); } } @@ -56,18 +34,6 @@ export class CommonMenuContribution implements MenuContribution { export class CommonCommandContribution implements CommandContribution { contribute(commandRegistry: CommandRegistry): void { - commandRegistry.registerCommand({ - id: CommonCommands.EDIT_CUT, - label: 'Cut' - }) - commandRegistry.registerCommand({ - id: CommonCommands.EDIT_COPY, - label: 'Copy', - }) - commandRegistry.registerCommand({ - id: CommonCommands.EDIT_PASTE, - label: 'Paste' - }) commandRegistry.registerCommand({ id: CommonCommands.EDIT_UNDO, label: 'Undo' diff --git a/src/editor/browser/editor-command.ts b/src/editor/browser/editor-command.ts index 6ce72c74a6e5c..d4e2534801536 100644 --- a/src/editor/browser/editor-command.ts +++ b/src/editor/browser/editor-command.ts @@ -31,13 +31,13 @@ export class EditorCommandHandler implements CommandHandler { } -export class ClipboardEditorCommandHandler extends EditorCommandHandler { +export class TextModificationEditorCommandHandler extends EditorCommandHandler { constructor(editorManager: IEditorManager, selectionService: SelectionService, id: string, - private commandArgs: (editorWidget: EditorWidget | undefined) => any[], - private doExecute: (editorWidget: EditorWidget | undefined, ...args: any[]) => any) { + private commandArgs: (widget: EditorWidget | undefined) => any[], + private doExecute: (widget: EditorWidget | undefined, ...args: any[]) => any) { super(editorManager, selectionService, id); } diff --git a/src/editor/browser/editor-module.ts b/src/editor/browser/editor-module.ts index 860a214161e4c..03bfa59cab918 100644 --- a/src/editor/browser/editor-module.ts +++ b/src/editor/browser/editor-module.ts @@ -3,7 +3,7 @@ import { SelectionService } from '../../application/common/selection-service'; import { CommandContribution, CommandRegistry, CommandHandler } from '../../application/common/command'; import { CommonCommands } from '../../application/common/commands-common'; import { MenuContribution, MenuModelRegistry } from '../../application/common/menu'; -import { EditorCommandHandler, ClipboardEditorCommandHandler } from './editor-command'; +import { EditorCommandHandler, TextModificationEditorCommandHandler } from './editor-command'; import { EditorManager, IEditorManager } from './editor-manager'; import { EditorRegistry } from './editor-registry'; import { EditorService } from './editor-service'; @@ -28,25 +28,11 @@ export class EditorCommandHandlers implements CommandContribution { contribute(registry: CommandRegistry) { - [CommonCommands.EDIT_CUT, CommonCommands.EDIT_COPY, CommonCommands.EDIT_PASTE].forEach(id => { - const commandArgs = (editorWidget: EditorWidget): any[] => { - return [{}]; - }; - const doExecute = (editorWidget: EditorWidget, ...args: any[]): any => { - return editorWidget.getControl()._commandService.executeCommand(id, args); - }; - const handler = this.newClipboardHandler(id, commandArgs, doExecute); - registry.registerHandler(id, handler); - }); - [CommonCommands.EDIT_UNDO, CommonCommands.EDIT_REDO].forEach(id => { - const commandArgs = (editorWidget: EditorWidget): any[] => { - return [{}]; - }; const doExecute = (editorWidget: EditorWidget, ...args: any[]): any => { return editorWidget.getControl().trigger('keyboard', id, args); }; - const handler = this.newClipboardHandler(id, commandArgs, doExecute); + const handler = this.newClipboardHandler(id, doExecute); registry.registerHandler(id, handler); }); @@ -77,11 +63,9 @@ export class EditorCommandHandlers implements CommandContribution { return new EditorCommandHandler(this.editorService, this.selectionService, id); } - private newClipboardHandler(id: string, - commandArgs: (editorWidget: EditorWidget) => any[], - doExecute: (editorWidget: EditorWidget, ...args: any[]) => any) { - - return new ClipboardEditorCommandHandler(this.editorService, this.selectionService, id, commandArgs, doExecute); + private newClipboardHandler(id: string, doExecute: (editorWidget: EditorWidget, ...args: any[]) => any) { + const commandArgs = (widget: EditorWidget) => [{}]; + return new TextModificationEditorCommandHandler(this.editorService, this.selectionService, id, commandArgs, doExecute); } } @@ -96,18 +80,9 @@ export class EditorMenuContribution implements MenuContribution { registry.registerMenuAction([EDITOR_CONTEXT_MENU_ID, "1_undo/redo"], { commandId: CommonCommands.EDIT_REDO }); - registry.registerMenuAction([EDITOR_CONTEXT_MENU_ID, "2_copy"], { - commandId: CommonCommands.EDIT_CUT - }); - registry.registerMenuAction([EDITOR_CONTEXT_MENU_ID, "2_copy"], { - commandId: CommonCommands.EDIT_COPY - }); - registry.registerMenuAction([EDITOR_CONTEXT_MENU_ID, "2_copy"], { - commandId: CommonCommands.EDIT_PASTE - }); const wrap: (item: IMenuItem) => { path: string[], commandId: string } = (item) => { - return { path: [EDITOR_CONTEXT_MENU_ID, (item.group || "")], commandId: item.command.id } + return { path: [EDITOR_CONTEXT_MENU_ID, (item.group || "")], commandId: item.command.id }; }; MenuRegistry.getMenuItems(MenuId.EditorContext) diff --git a/typings/monaco/index.d.ts b/typings/monaco/index.d.ts index 8d8a1b6ec572e..383f1cf1fa7f5 100644 --- a/typings/monaco/index.d.ts +++ b/typings/monaco/index.d.ts @@ -105,25 +105,6 @@ declare module monaco.editor { showContextMenu(delegate: IContextMenuDelegate): void; } - export interface ICommandService { - /** - * Executes the command with the given argument. - */ - executeCommand(commandId: string, ...args: any[]): Promise; - - /** - * Sugar for executing the command in type-safe way. - */ - executeCommand(commandId: string, ...args: any[]): Promise; - } - - export interface IStandaloneCodeEditor extends ICodeEditor { - /** - * The read-only command service for the code editor. - */ - readonly _commandService: ICommandService; - } - } declare module monaco.commands {