toggleTabFocusMode.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 { alert } from '../../../base/browser/ui/aria/aria.js';
  6. import { EditorAction, registerEditorAction } from '../../browser/editorExtensions.js';
  7. import { TabFocus } from '../../common/config/commonEditorConfig.js';
  8. import * as nls from '../../../nls.js';
  9. export class ToggleTabFocusModeAction extends EditorAction {
  10. constructor() {
  11. super({
  12. id: ToggleTabFocusModeAction.ID,
  13. label: nls.localize({ key: 'toggle.tabMovesFocus', comment: ['Turn on/off use of tab key for moving focus around VS Code'] }, "Toggle Tab Key Moves Focus"),
  14. alias: 'Toggle Tab Key Moves Focus',
  15. precondition: undefined,
  16. kbOpts: {
  17. kbExpr: null,
  18. primary: 2048 /* CtrlCmd */ | 43 /* KeyM */,
  19. mac: { primary: 256 /* WinCtrl */ | 1024 /* Shift */ | 43 /* KeyM */ },
  20. weight: 100 /* EditorContrib */
  21. }
  22. });
  23. }
  24. run(accessor, editor) {
  25. const oldValue = TabFocus.getTabFocusMode();
  26. const newValue = !oldValue;
  27. TabFocus.setTabFocusMode(newValue);
  28. if (newValue) {
  29. alert(nls.localize('toggle.tabMovesFocus.on', "Pressing Tab will now move focus to the next focusable element"));
  30. }
  31. else {
  32. alert(nls.localize('toggle.tabMovesFocus.off', "Pressing Tab will now insert the tab character"));
  33. }
  34. }
  35. }
  36. ToggleTabFocusModeAction.ID = 'editor.action.toggleTabFocusMode';
  37. registerEditorAction(ToggleTabFocusModeAction);