Skip to content

Commit

Permalink
Fixed #5500: implemented "Toggle Minimap" command
Browse files Browse the repository at this point in the history
- Implemented the "Toggle Minimap" command in the command pallete.

Signed-off-by: fangnx <naxin.fang@ericsson.com>
  • Loading branch information
fangnx authored and vince-fugnitto committed Jul 5, 2019
1 parent d4adca2 commit f247b57
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/editor/src/browser/editor-command.ts
Expand Up @@ -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()
Expand Down Expand Up @@ -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(),
Expand Down
16 changes: 16 additions & 0 deletions packages/editor/src/browser/editor-navigation-contribution.ts
Expand Up @@ -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 {
Expand All @@ -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;

Expand All @@ -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<void> {
Expand All @@ -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<void> {
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) {
Expand Down

0 comments on commit f247b57

Please sign in to comment.