Path: blob/main/src/vs/editor/contrib/stickyScroll/browser/stickyScrollActions.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 { KeyCode } from '../../../../base/common/keyCodes.js';6import { EditorAction2, ServicesAccessor } from '../../../browser/editorExtensions.js';7import { localize, localize2 } from '../../../../nls.js';8import { Categories } from '../../../../platform/action/common/actionCommonCategories.js';9import { MenuId } from '../../../../platform/actions/common/actions.js';10import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';11import { KeybindingWeight } from '../../../../platform/keybinding/common/keybindingsRegistry.js';12import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';13import { EditorContextKeys } from '../../../common/editorContextKeys.js';14import { ICodeEditor } from '../../../browser/editorBrowser.js';15import { StickyScrollController } from './stickyScrollController.js';1617export class ToggleStickyScroll extends EditorAction2 {1819constructor() {20super({21id: 'editor.action.toggleStickyScroll',22title: {23...localize2('toggleEditorStickyScroll', "Toggle Editor Sticky Scroll"),24mnemonicTitle: localize({ key: 'mitoggleStickyScroll', comment: ['&& denotes a mnemonic'] }, "&&Toggle Editor Sticky Scroll"),25},26metadata: {27description: localize2('toggleEditorStickyScroll.description', "Toggle/enable the editor sticky scroll which shows the nested scopes at the top of the viewport"),28},29category: Categories.View,30toggled: {31condition: ContextKeyExpr.equals('config.editor.stickyScroll.enabled', true),32title: localize('stickyScroll', "Sticky Scroll"),33mnemonicTitle: localize({ key: 'miStickyScroll', comment: ['&& denotes a mnemonic'] }, "&&Sticky Scroll"),34},35menu: [36{ id: MenuId.CommandPalette },37{ id: MenuId.MenubarAppearanceMenu, group: '4_editor', order: 3 },38{ id: MenuId.StickyScrollContext }39]40});41}4243async runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor): Promise<void> {44const configurationService = accessor.get(IConfigurationService);45const newValue = !configurationService.getValue('editor.stickyScroll.enabled');46const isFocused = StickyScrollController.get(editor)?.isFocused();47configurationService.updateValue('editor.stickyScroll.enabled', newValue);48if (isFocused) {49editor.focus();50}51}52}5354const weight = KeybindingWeight.EditorContrib;5556export class FocusStickyScroll extends EditorAction2 {5758constructor() {59super({60id: 'editor.action.focusStickyScroll',61title: {62...localize2('focusStickyScroll', "Focus Editor Sticky Scroll"),63mnemonicTitle: localize({ key: 'mifocusEditorStickyScroll', comment: ['&& denotes a mnemonic'] }, "&&Focus Editor Sticky Scroll"),64},65precondition: ContextKeyExpr.and(ContextKeyExpr.has('config.editor.stickyScroll.enabled'), EditorContextKeys.stickyScrollVisible),66menu: [67{ id: MenuId.CommandPalette },68]69});70}7172runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) {73StickyScrollController.get(editor)?.focus();74}75}7677export class SelectNextStickyScrollLine extends EditorAction2 {78constructor() {79super({80id: 'editor.action.selectNextStickyScrollLine',81title: localize2('selectNextStickyScrollLine.title', "Select the next editor sticky scroll line"),82precondition: EditorContextKeys.stickyScrollFocused.isEqualTo(true),83keybinding: {84weight,85primary: KeyCode.DownArrow86}87});88}8990runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) {91StickyScrollController.get(editor)?.focusNext();92}93}9495export class SelectPreviousStickyScrollLine extends EditorAction2 {96constructor() {97super({98id: 'editor.action.selectPreviousStickyScrollLine',99title: localize2('selectPreviousStickyScrollLine.title', "Select the previous sticky scroll line"),100precondition: EditorContextKeys.stickyScrollFocused.isEqualTo(true),101keybinding: {102weight,103primary: KeyCode.UpArrow104}105});106}107108runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) {109StickyScrollController.get(editor)?.focusPrevious();110}111}112113export class GoToStickyScrollLine extends EditorAction2 {114constructor() {115super({116id: 'editor.action.goToFocusedStickyScrollLine',117title: localize2('goToFocusedStickyScrollLine.title', "Go to the focused sticky scroll line"),118precondition: EditorContextKeys.stickyScrollFocused.isEqualTo(true),119keybinding: {120weight,121primary: KeyCode.Enter122}123});124}125126runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) {127StickyScrollController.get(editor)?.goToFocused();128}129}130131export class SelectEditor extends EditorAction2 {132133constructor() {134super({135id: 'editor.action.selectEditor',136title: localize2('selectEditor.title', "Select Editor"),137precondition: EditorContextKeys.stickyScrollFocused.isEqualTo(true),138keybinding: {139weight,140primary: KeyCode.Escape141}142});143}144145runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) {146StickyScrollController.get(editor)?.selectEditor();147}148}149150151