Path: blob/main/src/vs/editor/standalone/browser/toggleHighContrast/toggleHighContrast.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 { ICodeEditor } from '../../../browser/editorBrowser.js';6import { EditorAction, ServicesAccessor, registerEditorAction } from '../../../browser/editorExtensions.js';7import { IStandaloneThemeService } from '../../common/standaloneTheme.js';8import { ToggleHighContrastNLS } from '../../../common/standaloneStrings.js';9import { isDark, isHighContrast } from '../../../../platform/theme/common/theme.js';10import { HC_BLACK_THEME_NAME, HC_LIGHT_THEME_NAME, VS_DARK_THEME_NAME, VS_LIGHT_THEME_NAME } from '../standaloneThemeService.js';1112class ToggleHighContrast extends EditorAction {1314private _originalThemeName: string | null;1516constructor() {17super({18id: 'editor.action.toggleHighContrast',19label: ToggleHighContrastNLS.toggleHighContrast,20alias: 'Toggle High Contrast Theme',21precondition: undefined22});23this._originalThemeName = null;24}2526public run(accessor: ServicesAccessor, editor: ICodeEditor): void {27const standaloneThemeService = accessor.get(IStandaloneThemeService);28const currentTheme = standaloneThemeService.getColorTheme();29if (isHighContrast(currentTheme.type)) {30// We must toggle back to the integrator's theme31standaloneThemeService.setTheme(this._originalThemeName || (isDark(currentTheme.type) ? VS_DARK_THEME_NAME : VS_LIGHT_THEME_NAME));32this._originalThemeName = null;33} else {34standaloneThemeService.setTheme(isDark(currentTheme.type) ? HC_BLACK_THEME_NAME : HC_LIGHT_THEME_NAME);35this._originalThemeName = currentTheme.themeName;36}37}38}3940registerEditorAction(ToggleHighContrast);414243