Skip to content

Commit

Permalink
GH-22: Disabled the default Monaco context menu in editor.
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 4, 2017
1 parent 90c2a1d commit ba4d7e4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/editor/browser/editor-contextmenu.ts
Original file line number Diff line number Diff line change
@@ -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
}

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

Expand Down Expand Up @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion src/editor/browser/editor-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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) {
}

Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions typings/monaco/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ declare module monaco.editor {
export interface IEditorOverrideServices {
editorService?: IEditorService;
textModelResolverService?: ITextModelResolverService;
contextMenuService?: IContextMenuService;
}

export interface IResourceInput {
Expand Down Expand Up @@ -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;
}

}

0 comments on commit ba4d7e4

Please sign in to comment.