From ba4d7e4e8c7d03de1330baf90654c8f20f447ceb Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Tue, 4 Apr 2017 10:43:07 +0200 Subject: [PATCH] GH-22: Disabled the default Monaco context menu in editor. Signed-off-by: Akos Kitta --- src/editor/browser/editor-contextmenu.ts | 13 +++++++++++++ src/editor/browser/editor-module.ts | 2 ++ src/editor/browser/editor-service.ts | 6 +++++- typings/monaco/index.d.ts | 8 ++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/editor/browser/editor-contextmenu.ts diff --git a/src/editor/browser/editor-contextmenu.ts b/src/editor/browser/editor-contextmenu.ts new file mode 100644 index 0000000000000..dd2a1fbdc42ce --- /dev/null +++ b/src/editor/browser/editor-contextmenu.ts @@ -0,0 +1,13 @@ +import { injectable } from "inversify"; +import IContextMenuService = monaco.editor.IContextMenuService; + +export const IContextMenuService = Symbol("IContextMenuService"); + +@injectable() +export class NoopContextMenuService implements IContextMenuService { + + showContextMenu(delegate: any): void { + // NOOP + } + +} diff --git a/src/editor/browser/editor-module.ts b/src/editor/browser/editor-module.ts index 6614719d0a9ee..934b80802c13a 100644 --- a/src/editor/browser/editor-module.ts +++ b/src/editor/browser/editor-module.ts @@ -9,6 +9,7 @@ import { EditorRegistry } from './editor-registry'; import { EditorService } from './editor-service'; import { TextModelResolverService } from './model-resolver-service'; import { ContainerModule, inject, injectable } from 'inversify'; +import { NoopContextMenuService } from './editor-contextmenu'; export const EDITOR_CONTEXT = 'editor_context_menu'; @@ -75,6 +76,7 @@ export class EditorMenuContribution implements MenuContribution { export const editorModule = new ContainerModule(bind => { bind(EditorRegistry).toSelf().inSingletonScope(); + bind(NoopContextMenuService).toSelf().inSingletonScope(); bind(EditorService).toSelf().inSingletonScope(); bind(TextModelResolverService).toSelf().inSingletonScope(); bind(IEditorManager).to(EditorManager).inSingletonScope(); diff --git a/src/editor/browser/editor-service.ts b/src/editor/browser/editor-service.ts index a262c3c703b91..139733d4a794b 100644 --- a/src/editor/browser/editor-service.ts +++ b/src/editor/browser/editor-service.ts @@ -4,8 +4,10 @@ import { EditorRegistry } from './editor-registry'; import { EditorWidget } from './editor-widget'; import { TextModelResolverService } from './model-resolver-service'; import { injectable, inject } from 'inversify'; +import { NoopContextMenuService } from './editor-contextmenu'; import IEditorService = monaco.editor.IEditorService; import IResourceInput = monaco.editor.IResourceInput; +import IContextMenuService = monaco.editor.IContextMenuService; import Uri = monaco.Uri; @injectable() @@ -15,6 +17,7 @@ export class EditorService implements IEditorService { constructor(protected readonly editorRegistry: EditorRegistry, protected readonly textModelResolverService: TextModelResolverService, + @inject(NoopContextMenuService) protected readonly contextMenuService: IContextMenuService, @inject(SelectionService) protected readonly selectionService: SelectionService) { } @@ -49,7 +52,8 @@ export class EditorService implements IEditorService { theme: 'vs-dark' }, { editorService: this, - textModelResolverService: this.textModelResolverService + textModelResolverService: this.textModelResolverService, + contextMenuService: this.contextMenuService }, this.selectionService); editor.disposed.connect(() => reference.dispose()); editor.title.closable = true; diff --git a/typings/monaco/index.d.ts b/typings/monaco/index.d.ts index 28484ea535f44..8e5accd7e2c99 100644 --- a/typings/monaco/index.d.ts +++ b/typings/monaco/index.d.ts @@ -5,6 +5,7 @@ declare module monaco.editor { export interface IEditorOverrideServices { editorService?: IEditorService; textModelResolverService?: ITextModelResolverService; + contextMenuService?: IContextMenuService; } export interface IResourceInput { @@ -90,4 +91,11 @@ declare module monaco.editor { textEditorModel: monaco.editor.IModel; } + export interface IContextMenuService { + /** + * Shows the native Monaco context menu in the editor. + */ + showContextMenu(delegate: any): void; + } + }