Skip to content

Commit

Permalink
GH-22: Removed cut/cop/paste common commands.
Browse files Browse the repository at this point in the history
Signed-off-by: Akos Kitta <kittaakos@gmail.com>
  • Loading branch information
kittaakos committed Apr 12, 2017
1 parent 222592b commit 64e22a8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 87 deletions.
34 changes: 0 additions & 34 deletions src/application/common/commands-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
});
}

}
Expand All @@ -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'
Expand Down
6 changes: 3 additions & 3 deletions src/editor/browser/editor-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
37 changes: 6 additions & 31 deletions src/editor/browser/editor-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
});

Expand Down Expand Up @@ -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);
}

}
Expand All @@ -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)
Expand Down
19 changes: 0 additions & 19 deletions typings/monaco/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>;

/**
* Sugar for executing the command in type-safe way.
*/
executeCommand<T>(commandId: string, ...args: any[]): Promise<T>;
}

export interface IStandaloneCodeEditor extends ICodeEditor {
/**
* The read-only command service for the code editor.
*/
readonly _commandService: ICommandService;
}

}

declare module monaco.commands {
Expand Down

0 comments on commit 64e22a8

Please sign in to comment.