b8f3b2dae4c882063bd56cf61ac0297b4b6f6170d76d9a24595ade8c414bab2afaac49a5a8bbd2f636391e02f7c86ee7a13ccd447a9b555317dd644560bcfd 1.8 KB

12345678910111213141516171819202122232425262728293031323334
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. import { EditorAction, registerEditorAction } from '../../../browser/editorExtensions.js';
  6. import { IStandaloneThemeService } from '../../common/standaloneTheme.js';
  7. import { ToggleHighContrastNLS } from '../../../common/standaloneStrings.js';
  8. import { isDark, isHighContrast } from '../../../../platform/theme/common/theme.js';
  9. import { HC_BLACK_THEME_NAME, HC_LIGHT_THEME_NAME, VS_DARK_THEME_NAME, VS_LIGHT_THEME_NAME } from '../standaloneThemeService.js';
  10. class ToggleHighContrast extends EditorAction {
  11. constructor() {
  12. super({
  13. id: 'editor.action.toggleHighContrast',
  14. label: ToggleHighContrastNLS.toggleHighContrast,
  15. alias: 'Toggle High Contrast Theme',
  16. precondition: undefined
  17. });
  18. this._originalThemeName = null;
  19. }
  20. run(accessor, editor) {
  21. const standaloneThemeService = accessor.get(IStandaloneThemeService);
  22. const currentTheme = standaloneThemeService.getColorTheme();
  23. if (isHighContrast(currentTheme.type)) {
  24. // We must toggle back to the integrator's theme
  25. standaloneThemeService.setTheme(this._originalThemeName || (isDark(currentTheme.type) ? VS_DARK_THEME_NAME : VS_LIGHT_THEME_NAME));
  26. this._originalThemeName = null;
  27. }
  28. else {
  29. standaloneThemeService.setTheme(isDark(currentTheme.type) ? HC_BLACK_THEME_NAME : HC_LIGHT_THEME_NAME);
  30. this._originalThemeName = currentTheme.themeName;
  31. }
  32. }
  33. }
  34. registerEditorAction(ToggleHighContrast);