Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/standalone/browser/toggleHighContrast/toggleHighContrast.ts
3296 views
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
6
import { ICodeEditor } from '../../../browser/editorBrowser.js';
7
import { EditorAction, ServicesAccessor, registerEditorAction } from '../../../browser/editorExtensions.js';
8
import { IStandaloneThemeService } from '../../common/standaloneTheme.js';
9
import { ToggleHighContrastNLS } from '../../../common/standaloneStrings.js';
10
import { isDark, isHighContrast } from '../../../../platform/theme/common/theme.js';
11
import { HC_BLACK_THEME_NAME, HC_LIGHT_THEME_NAME, VS_DARK_THEME_NAME, VS_LIGHT_THEME_NAME } from '../standaloneThemeService.js';
12
13
class ToggleHighContrast extends EditorAction {
14
15
private _originalThemeName: string | null;
16
17
constructor() {
18
super({
19
id: 'editor.action.toggleHighContrast',
20
label: ToggleHighContrastNLS.toggleHighContrast,
21
alias: 'Toggle High Contrast Theme',
22
precondition: undefined
23
});
24
this._originalThemeName = null;
25
}
26
27
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
28
const standaloneThemeService = accessor.get(IStandaloneThemeService);
29
const currentTheme = standaloneThemeService.getColorTheme();
30
if (isHighContrast(currentTheme.type)) {
31
// We must toggle back to the integrator's theme
32
standaloneThemeService.setTheme(this._originalThemeName || (isDark(currentTheme.type) ? VS_DARK_THEME_NAME : VS_LIGHT_THEME_NAME));
33
this._originalThemeName = null;
34
} else {
35
standaloneThemeService.setTheme(isDark(currentTheme.type) ? HC_BLACK_THEME_NAME : HC_LIGHT_THEME_NAME);
36
this._originalThemeName = currentTheme.themeName;
37
}
38
}
39
}
40
41
registerEditorAction(ToggleHighContrast);
42
43