From f247b57b0ce72fdbe2db701d5eb9bfef31d44889 Mon Sep 17 00:00:00 2001 From: fangnx Date: Tue, 2 Jul 2019 16:42:25 -0400 Subject: [PATCH] Fixed #5500: implemented "Toggle Minimap" command - Implemented the "Toggle Minimap" command in the command pallete. Signed-off-by: fangnx --- packages/editor/src/browser/editor-command.ts | 9 +++++++++ .../browser/editor-navigation-contribution.ts | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/packages/editor/src/browser/editor-command.ts b/packages/editor/src/browser/editor-command.ts index e3109061d7824..f8d4daaafca01 100644 --- a/packages/editor/src/browser/editor-command.ts +++ b/packages/editor/src/browser/editor-command.ts @@ -100,6 +100,14 @@ export namespace EditorCommands { category: 'View', label: 'Show All Opened Editors' }; + /** + * Command that toggles the minimap. + */ + export const TOGGLE_MINIMAP: Command = { + id: 'editor.action.toggleMinimap', + category: 'View', + label: 'Toggle Minimap' + }; } @injectable() @@ -138,6 +146,7 @@ export class EditorCommandContribution implements CommandContribution { registry.registerCommand(EditorCommands.GO_FORWARD); registry.registerCommand(EditorCommands.GO_LAST_EDIT); registry.registerCommand(EditorCommands.CLEAR_EDITOR_HISTORY); + registry.registerCommand(EditorCommands.TOGGLE_MINIMAP); registry.registerCommand(CommonCommands.AUTO_SAVE, { isToggled: () => this.isAutoSaveOn(), diff --git a/packages/editor/src/browser/editor-navigation-contribution.ts b/packages/editor/src/browser/editor-navigation-contribution.ts index 7fda5fd6dfb0f..9cb2ab7964605 100644 --- a/packages/editor/src/browser/editor-navigation-contribution.ts +++ b/packages/editor/src/browser/editor-navigation-contribution.ts @@ -26,6 +26,7 @@ import { EditorManager } from './editor-manager'; import { TextEditor, Position, Range, TextDocumentChangeEvent } from './editor'; import { NavigationLocation } from './navigation/navigation-location'; import { NavigationLocationService } from './navigation/navigation-location-service'; +import { PreferenceService, PreferenceScope } from '@theia/core/lib/browser'; @injectable() export class EditorNavigationContribution implements Disposable, FrontendApplicationContribution { @@ -47,6 +48,9 @@ export class EditorNavigationContribution implements Disposable, FrontendApplica @inject(StorageService) protected readonly storageService: StorageService; + @inject(PreferenceService) + protected readonly preferenceService: PreferenceService; + @inject(CommandRegistry) protected readonly commandRegistry: CommandRegistry; @@ -73,6 +77,10 @@ export class EditorNavigationContribution implements Disposable, FrontendApplica execute: () => this.locationStack.clearHistory(), isEnabled: () => this.locationStack.locations().length > 0 }); + this.commandRegistry.registerHandler(EditorCommands.TOGGLE_MINIMAP.id, { + execute: () => this.toggleMinimap(), + isEnabled: () => true + }); } async onStart(): Promise { @@ -88,6 +96,14 @@ export class EditorNavigationContribution implements Disposable, FrontendApplica this.toDispose.dispose(); } + /** + * Toggle the display of minimap in the editor. + */ + protected async toggleMinimap(): Promise { + const value: boolean | undefined = this.preferenceService.get('editor.minimap.enabled'); + this.preferenceService.set('editor.minimap.enabled', !value, PreferenceScope.User); + } + protected onCurrentEditorChanged(editorWidget: EditorWidget | undefined): void { this.toDisposePerCurrentEditor.dispose(); if (editorWidget) {