Path: blob/main/src/vs/workbench/contrib/codeEditor/browser/toggleRenderWhitespace.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { localize, localize2 } from '../../../../nls.js';6import { Action2, MenuId, registerAction2 } from '../../../../platform/actions/common/actions.js';7import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';8import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';9import { Categories } from '../../../../platform/action/common/actionCommonCategories.js';10import { ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js';1112class ToggleRenderWhitespaceAction extends Action2 {1314static readonly ID = 'editor.action.toggleRenderWhitespace';1516constructor() {17super({18id: ToggleRenderWhitespaceAction.ID,19title: {20...localize2('toggleRenderWhitespace', "Toggle Render Whitespace"),21mnemonicTitle: localize({ key: 'miToggleRenderWhitespace', comment: ['&& denotes a mnemonic'] }, "&&Render Whitespace"),22},23category: Categories.View,24f1: true,25toggled: ContextKeyExpr.notEquals('config.editor.renderWhitespace', 'none'),26menu: {27id: MenuId.MenubarAppearanceMenu,28group: '4_editor',29order: 430}31});32}3334override run(accessor: ServicesAccessor): Promise<void> {35const configurationService = accessor.get(IConfigurationService);3637const renderWhitespace = configurationService.getValue<string>('editor.renderWhitespace');3839let newRenderWhitespace: string;40if (renderWhitespace === 'none') {41newRenderWhitespace = 'all';42} else {43newRenderWhitespace = 'none';44}4546return configurationService.updateValue('editor.renderWhitespace', newRenderWhitespace);47}48}4950registerAction2(ToggleRenderWhitespaceAction);515253