Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/contrib/stickyScroll/browser/stickyScrollActions.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 { KeyCode } from '../../../../base/common/keyCodes.js';
7
import { EditorAction2, ServicesAccessor } from '../../../browser/editorExtensions.js';
8
import { localize, localize2 } from '../../../../nls.js';
9
import { Categories } from '../../../../platform/action/common/actionCommonCategories.js';
10
import { MenuId } from '../../../../platform/actions/common/actions.js';
11
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
12
import { KeybindingWeight } from '../../../../platform/keybinding/common/keybindingsRegistry.js';
13
import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';
14
import { EditorContextKeys } from '../../../common/editorContextKeys.js';
15
import { ICodeEditor } from '../../../browser/editorBrowser.js';
16
import { StickyScrollController } from './stickyScrollController.js';
17
18
export class ToggleStickyScroll extends EditorAction2 {
19
20
constructor() {
21
super({
22
id: 'editor.action.toggleStickyScroll',
23
title: {
24
...localize2('toggleEditorStickyScroll', "Toggle Editor Sticky Scroll"),
25
mnemonicTitle: localize({ key: 'mitoggleStickyScroll', comment: ['&& denotes a mnemonic'] }, "&&Toggle Editor Sticky Scroll"),
26
},
27
metadata: {
28
description: localize2('toggleEditorStickyScroll.description', "Toggle/enable the editor sticky scroll which shows the nested scopes at the top of the viewport"),
29
},
30
category: Categories.View,
31
toggled: {
32
condition: ContextKeyExpr.equals('config.editor.stickyScroll.enabled', true),
33
title: localize('stickyScroll', "Sticky Scroll"),
34
mnemonicTitle: localize({ key: 'miStickyScroll', comment: ['&& denotes a mnemonic'] }, "&&Sticky Scroll"),
35
},
36
menu: [
37
{ id: MenuId.CommandPalette },
38
{ id: MenuId.MenubarAppearanceMenu, group: '4_editor', order: 3 },
39
{ id: MenuId.StickyScrollContext }
40
]
41
});
42
}
43
44
async runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor): Promise<void> {
45
const configurationService = accessor.get(IConfigurationService);
46
const newValue = !configurationService.getValue('editor.stickyScroll.enabled');
47
const isFocused = StickyScrollController.get(editor)?.isFocused();
48
configurationService.updateValue('editor.stickyScroll.enabled', newValue);
49
if (isFocused) {
50
editor.focus();
51
}
52
}
53
}
54
55
const weight = KeybindingWeight.EditorContrib;
56
57
export class FocusStickyScroll extends EditorAction2 {
58
59
constructor() {
60
super({
61
id: 'editor.action.focusStickyScroll',
62
title: {
63
...localize2('focusStickyScroll', "Focus Editor Sticky Scroll"),
64
mnemonicTitle: localize({ key: 'mifocusEditorStickyScroll', comment: ['&& denotes a mnemonic'] }, "&&Focus Editor Sticky Scroll"),
65
},
66
precondition: ContextKeyExpr.and(ContextKeyExpr.has('config.editor.stickyScroll.enabled'), EditorContextKeys.stickyScrollVisible),
67
menu: [
68
{ id: MenuId.CommandPalette },
69
]
70
});
71
}
72
73
runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) {
74
StickyScrollController.get(editor)?.focus();
75
}
76
}
77
78
export class SelectNextStickyScrollLine extends EditorAction2 {
79
constructor() {
80
super({
81
id: 'editor.action.selectNextStickyScrollLine',
82
title: localize2('selectNextStickyScrollLine.title', "Select the next editor sticky scroll line"),
83
precondition: EditorContextKeys.stickyScrollFocused.isEqualTo(true),
84
keybinding: {
85
weight,
86
primary: KeyCode.DownArrow
87
}
88
});
89
}
90
91
runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) {
92
StickyScrollController.get(editor)?.focusNext();
93
}
94
}
95
96
export class SelectPreviousStickyScrollLine extends EditorAction2 {
97
constructor() {
98
super({
99
id: 'editor.action.selectPreviousStickyScrollLine',
100
title: localize2('selectPreviousStickyScrollLine.title', "Select the previous sticky scroll line"),
101
precondition: EditorContextKeys.stickyScrollFocused.isEqualTo(true),
102
keybinding: {
103
weight,
104
primary: KeyCode.UpArrow
105
}
106
});
107
}
108
109
runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) {
110
StickyScrollController.get(editor)?.focusPrevious();
111
}
112
}
113
114
export class GoToStickyScrollLine extends EditorAction2 {
115
constructor() {
116
super({
117
id: 'editor.action.goToFocusedStickyScrollLine',
118
title: localize2('goToFocusedStickyScrollLine.title', "Go to the focused sticky scroll line"),
119
precondition: EditorContextKeys.stickyScrollFocused.isEqualTo(true),
120
keybinding: {
121
weight,
122
primary: KeyCode.Enter
123
}
124
});
125
}
126
127
runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) {
128
StickyScrollController.get(editor)?.goToFocused();
129
}
130
}
131
132
export class SelectEditor extends EditorAction2 {
133
134
constructor() {
135
super({
136
id: 'editor.action.selectEditor',
137
title: localize2('selectEditor.title', "Select Editor"),
138
precondition: EditorContextKeys.stickyScrollFocused.isEqualTo(true),
139
keybinding: {
140
weight,
141
primary: KeyCode.Escape
142
}
143
});
144
}
145
146
runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) {
147
StickyScrollController.get(editor)?.selectEditor();
148
}
149
}
150
151