@opensumi/ide-keymaps 2.21.13 → 2.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,202 @@
1
+ import { Autowired, Injectable } from '@opensumi/di';
2
+ import {
3
+ ClientAppContribution,
4
+ URI,
5
+ Domain,
6
+ CommandContribution,
7
+ CommandRegistry,
8
+ Command,
9
+ COMMON_COMMANDS,
10
+ KeybindingContribution,
11
+ KeybindingRegistry,
12
+ WithEventBus,
13
+ MaybePromise,
14
+ localize,
15
+ getIcon,
16
+ KeyboardNativeLayoutService,
17
+ KEYBOARD_COMMANDS,
18
+ getKeyboardLayoutId,
19
+ KeymapInfo,
20
+ formatLocalize,
21
+ } from '@opensumi/ide-core-browser';
22
+ import { MenuContribution, IMenuRegistry, MenuId } from '@opensumi/ide-core-browser/lib/menu/next';
23
+ import { ResourceService, IResourceProvider, IResource } from '@opensumi/ide-editor';
24
+ import { BrowserEditorContribution, EditorComponentRegistry, EditorOpenType } from '@opensumi/ide-editor/lib/browser';
25
+ import { IFileServiceClient } from '@opensumi/ide-file-service/lib/common';
26
+ import { QuickPickItem, QuickPickService } from '@opensumi/ide-quick-open';
27
+
28
+ import { KEYMAPS_SCHEME, IKeymapService } from '../common';
29
+
30
+ import { KeymapsView } from './keymaps.view';
31
+
32
+ const KEYMAPS_PREVIEW_COMPONENT_ID = 'keymaps-preview';
33
+
34
+ @Injectable()
35
+ export class KeymapsResourceProvider extends WithEventBus implements IResourceProvider {
36
+ readonly scheme: string = KEYMAPS_SCHEME;
37
+
38
+ constructor() {
39
+ super();
40
+ }
41
+
42
+ provideResource(uri: URI): MaybePromise<IResource<any>> {
43
+ return {
44
+ supportsRevive: true,
45
+ name: localize('keymaps.tab.name'),
46
+ icon: getIcon('setting'),
47
+ uri,
48
+ };
49
+ }
50
+
51
+ provideResourceSubname(resource: IResource, groupResources: IResource[]): string | null {
52
+ return null;
53
+ }
54
+
55
+ async shouldCloseResource(resource: IResource, openedResources: IResource[][]): Promise<boolean> {
56
+ return true;
57
+ }
58
+ }
59
+
60
+ export namespace KeymapsContextMenu {
61
+ // 1_, 2_用于菜单排序,这样能保证分组顺序顺序
62
+ export const KEYMAPS = '2_keymaps';
63
+ }
64
+
65
+ export namespace KEYMAP_COMMANDS {
66
+ const CATEGORY = 'keymaps';
67
+
68
+ export const OPEN_SOURCE_FILE: Command = {
69
+ id: 'keymaps.open.source',
70
+ label: localize('keymaps.editorTitle.openSource'),
71
+ category: CATEGORY,
72
+ };
73
+ }
74
+
75
+ @Domain(CommandContribution, KeybindingContribution, ClientAppContribution, BrowserEditorContribution, MenuContribution)
76
+ export class KeymapsContribution
77
+ implements
78
+ CommandContribution,
79
+ KeybindingContribution,
80
+ ClientAppContribution,
81
+ BrowserEditorContribution,
82
+ MenuContribution
83
+ {
84
+ @Autowired(QuickPickService)
85
+ private readonly quickPickService: QuickPickService;
86
+
87
+ @Autowired(KeyboardNativeLayoutService)
88
+ private readonly layoutProvider: KeyboardNativeLayoutService;
89
+
90
+ @Autowired(IFileServiceClient)
91
+ protected readonly filesystem: IFileServiceClient;
92
+
93
+ @Autowired(KeymapsResourceProvider)
94
+ protected readonly keymapsResourceProvider: KeymapsResourceProvider;
95
+
96
+ @Autowired(IKeymapService)
97
+ protected readonly keymapService: IKeymapService;
98
+
99
+ registerCommands(commands: CommandRegistry) {
100
+ commands.registerCommand(COMMON_COMMANDS.OPEN_KEYMAPS, {
101
+ isEnabled: () => true,
102
+ execute: async () => {
103
+ await this.keymapService.open();
104
+ },
105
+ });
106
+ commands.registerCommand(KEYMAP_COMMANDS.OPEN_SOURCE_FILE, {
107
+ execute: async () => {
108
+ this.keymapService.openResource();
109
+ },
110
+ });
111
+ commands.registerCommand(KEYBOARD_COMMANDS.CHOOSE_KEYBOARD_LAYOUT, {
112
+ execute: () => {
113
+ this.chooseLayout();
114
+ },
115
+ });
116
+ }
117
+
118
+ registerMenus(menus: IMenuRegistry) {
119
+ menus.registerMenuItem(MenuId.SettingsIconMenu, {
120
+ command: COMMON_COMMANDS.OPEN_KEYMAPS.id,
121
+ group: KeymapsContextMenu.KEYMAPS,
122
+ });
123
+
124
+ menus.registerMenuItem(MenuId.EditorTitle, {
125
+ command: KEYMAP_COMMANDS.OPEN_SOURCE_FILE.id,
126
+ iconClass: getIcon('open'),
127
+ group: 'navigation',
128
+ order: 4,
129
+ when: `resourceScheme == ${KEYMAPS_SCHEME}`,
130
+ });
131
+
132
+ menus.registerMenuItem(MenuId.EditorTitle, {
133
+ command: COMMON_COMMANDS.OPEN_KEYMAPS.id,
134
+ iconClass: getIcon('open'),
135
+ group: 'navigation',
136
+ order: 4,
137
+ when: 'resourceFilename =~ /keymaps.json/',
138
+ });
139
+ }
140
+
141
+ registerKeybindings(keybindings: KeybindingRegistry): void {
142
+ keybindings.registerKeybinding({
143
+ command: COMMON_COMMANDS.OPEN_KEYMAPS.id,
144
+ keybinding: 'ctrlcmd+K ctrlcmd+S',
145
+ });
146
+ }
147
+
148
+ onStart() {
149
+ this.keymapService.init();
150
+ }
151
+
152
+ registerResource(resourceService: ResourceService) {
153
+ resourceService.registerResourceProvider(this.keymapsResourceProvider);
154
+ }
155
+
156
+ registerEditorComponent(editorComponentRegistry: EditorComponentRegistry) {
157
+ editorComponentRegistry.registerEditorComponent({
158
+ component: KeymapsView,
159
+ uid: KEYMAPS_PREVIEW_COMPONENT_ID,
160
+ scheme: KEYMAPS_SCHEME,
161
+ });
162
+
163
+ editorComponentRegistry.registerEditorComponentResolver(KEYMAPS_SCHEME, (_, __, resolve) => {
164
+ resolve!([
165
+ {
166
+ type: EditorOpenType.component,
167
+ componentId: KEYMAPS_PREVIEW_COMPONENT_ID,
168
+ },
169
+ ]);
170
+ });
171
+ }
172
+
173
+ protected async chooseLayout() {
174
+ const current = this.layoutProvider.currentLayoutData;
175
+ const autodetect: QuickPickItem<'autodetect'> = {
176
+ label: localize('keyboard.autoDetect.label'),
177
+ description:
178
+ current && this.layoutProvider.currentLayoutSource !== 'user-choice'
179
+ ? formatLocalize('keyboard.autoDetect.description', getKeyboardLayoutId(current.layout))
180
+ : undefined,
181
+ detail: localize('keyboard.autoDetect.detail'),
182
+ value: 'autodetect',
183
+ };
184
+ const otherLayouts = this.layoutProvider.allLayoutData.map((layout) =>
185
+ this.toQuickPickValue(layout, current === layout),
186
+ );
187
+
188
+ let layouts: QuickPickItem<KeymapInfo | 'autodetect'>[];
189
+ layouts = [autodetect, ...otherLayouts];
190
+ const chosen = await this.quickPickService.show(layouts, { placeholder: 'Choose a keyboard layout' });
191
+ if (chosen) {
192
+ return this.layoutProvider.setLayoutData(chosen);
193
+ }
194
+ }
195
+
196
+ protected toQuickPickValue(layout: KeymapInfo, isCurrent: boolean): QuickPickItem<KeymapInfo> {
197
+ return {
198
+ label: getKeyboardLayoutId(layout.layout),
199
+ value: layout,
200
+ };
201
+ }
202
+ }
@@ -0,0 +1,409 @@
1
+ .keybinding_container {
2
+ padding: 11px 0 0 27px;
3
+ display: flex;
4
+ flex-direction: column;
5
+ height: 100%;
6
+ box-sizing: border-box;
7
+ width: calc(100% - 22px);
8
+ &:hover {
9
+ .keybinding_list_item_box {
10
+ border-left: 1px solid var(--sideBar-border);
11
+ border-bottom: 1px solid var(--sideBar-border);
12
+ &:nth-child(4) {
13
+ border-right: 1px solid var(--sideBar-border);
14
+ }
15
+ }
16
+ .keybinding_header {
17
+ border-top: 1px solid var(--sideBar-border);
18
+ border-bottom: 1px solid var(--sideBar-border);
19
+ .keybinding_header_item {
20
+ border-left: 1px solid var(--sideBar-border);
21
+ &:nth-child(4) {
22
+ border-right: 1px solid var(--sideBar-border);
23
+ }
24
+ }
25
+ }
26
+ }
27
+ }
28
+
29
+ .keybinding_searchbar {
30
+ padding: 0 0 10px 0;
31
+ display: flex;
32
+ flex-direction: row;
33
+ box-sizing: content-box;
34
+ font-size: 14px;
35
+ }
36
+
37
+ .keybinding_header {
38
+ display: flex;
39
+ flex-direction: row;
40
+ box-sizing: border-box;
41
+ font-size: 13px;
42
+ font-weight: bolder;
43
+ height: 40px;
44
+ line-height: 40px;
45
+ border-top: 1px solid transparent;
46
+ border-bottom: 1px solid transparent;
47
+ .keybinding_header_item {
48
+ &:nth-child(4) {
49
+ border-right: 1px solid transparent;
50
+ }
51
+ }
52
+ }
53
+
54
+ .keybinding_body {
55
+ position: relative;
56
+ height: calc(100% - 56px);
57
+ overflow: hidden;
58
+ display: flex;
59
+ flex-direction: column;
60
+ .keybinding_loading {
61
+ position: absolute;
62
+ width: 100%;
63
+ height: 100%;
64
+ background: var(--background);
65
+ opacity: 0.3;
66
+ top: 0;
67
+ left: 0;
68
+ }
69
+ }
70
+
71
+ .keybinding_list {
72
+ flex: 1;
73
+ }
74
+
75
+ .keybinding_list_header {
76
+ background-color: hsla(0, 0%, 51%, 0.04);
77
+ height: 30px;
78
+ line-height: 30px;
79
+ }
80
+
81
+ .keybinding_key_input_container {
82
+ position: relative;
83
+ height: 30px;
84
+ width: 100%;
85
+ &:hover {
86
+ .keybinding_optional_actions {
87
+ z-index: 999;
88
+ display: flex;
89
+ }
90
+ .keybinding_key_input_placeholder {
91
+ display: none;
92
+ }
93
+ }
94
+ }
95
+
96
+ .keybinding_detective_messages {
97
+ z-index: 100;
98
+ position: absolute;
99
+ left: 0;
100
+ top: 40px;
101
+ max-height: 175px;
102
+ min-width: 100%;
103
+ padding: 10px;
104
+ max-width: 600px;
105
+ background: var(--kt-selectDropdown-background);
106
+ box-shadow: 0 9px 28px 8px rgba(0, 0, 0, 0.15), 0 6px 16px 0 rgba(0, 0, 0, 0.4), 0 3px 6px -4px rgba(0, 0, 0, 0.4);
107
+ border-radius: 2px;
108
+ overflow-y: scroll;
109
+ overflow-x: hidden;
110
+ .keybinding_detective_messages_label {
111
+ color: var(--descriptionForeground);
112
+ text-align: left;
113
+ line-height: 20px;
114
+ font-size: 12px;
115
+ text-align: left;
116
+ line-height: 20px;
117
+ width: 172px;
118
+ height: 20px;
119
+ overflow: hidden;
120
+ text-overflow: ellipsis;
121
+ white-space: nowrap;
122
+ margin-bottom: 5px;
123
+ }
124
+ ul,
125
+ li {
126
+ margin: 0;
127
+ padding: 0;
128
+ }
129
+ .keybinding_detective_messages_container {
130
+ display: flex;
131
+ flex-direction: column;
132
+
133
+ .keybinding_detective_messages_item {
134
+ display: flex;
135
+ flex-direction: column;
136
+ .title {
137
+ text-align: left;
138
+ line-height: 20px;
139
+ font-size: 12px;
140
+ color: var(--foreground);
141
+ text-align: left;
142
+ line-height: 20px;
143
+ height: 20px;
144
+ width: 100%;
145
+ overflow: hidden;
146
+ text-overflow: ellipsis;
147
+ white-space: nowrap;
148
+ }
149
+ .description {
150
+ text-align: left;
151
+ line-height: 20px;
152
+ font-size: 12px;
153
+ color: var(--descriptionForeground);
154
+ text-align: left;
155
+ line-height: 20px;
156
+ height: 20px;
157
+ width: 100%;
158
+ overflow: hidden;
159
+ text-overflow: ellipsis;
160
+ white-space: nowrap;
161
+
162
+ display: flex;
163
+ align-items: center;
164
+ }
165
+ }
166
+ }
167
+ }
168
+
169
+ .keybinding_key_input_placeholder {
170
+ z-index: 100;
171
+ position: absolute;
172
+ right: 5px;
173
+ top: 0;
174
+ align-items: center;
175
+ justify-content: center;
176
+ color: var(--inputicon-foreground);
177
+ width: 16px;
178
+ height: 40px;
179
+ line-height: 40px;
180
+ text-align: center;
181
+ }
182
+
183
+ .keybinding_key_input,
184
+ .keybinding_key {
185
+ width: 100%;
186
+ height: 100%;
187
+ display: flex;
188
+ align-items: center;
189
+ justify-content: flex-start;
190
+ position: relative;
191
+ overflow: hidden;
192
+ }
193
+
194
+ .keybinding_key_block {
195
+ display: flex;
196
+ margin-right: 5px;
197
+ }
198
+
199
+ .keybinding_key_item {
200
+ display: block;
201
+ border-radius: 2px;
202
+ background-color: rgba(134, 140, 145, 0.1);
203
+ font-size: 12px;
204
+ padding: 1px 6px;
205
+ height: 20px;
206
+ line-height: 17px;
207
+ margin-right: 3px;
208
+ text-align: center;
209
+ border-bottom: 2px solid rgba(25, 25, 25, 0.1);
210
+ }
211
+
212
+ .keybinding_list_container {
213
+ width: 100%;
214
+ border-spacing: 0;
215
+ border-collapse: separate;
216
+ height: calc(100% - 30px);
217
+ span {
218
+ display: inline-block;
219
+ }
220
+ }
221
+
222
+ .keybinding_list_item {
223
+ cursor: default;
224
+ display: flex;
225
+ height: 40px;
226
+ flex-direction: row;
227
+ line-height: 40px;
228
+ position: relative;
229
+ match {
230
+ color: #ff7673;
231
+ }
232
+
233
+ .keybinding_list_item_box {
234
+ align-items: center;
235
+ width: 25%;
236
+ font-size: 12px;
237
+ border-left: 1px solid transparent;
238
+ border-bottom: 1px solid transparent;
239
+ box-sizing: border-box;
240
+ padding-left: 30px;
241
+ height: 40px;
242
+ position: relative;
243
+ display: flex;
244
+ align-items: center;
245
+ justify-content: flex-start;
246
+ &:nth-child(1) {
247
+ width: 30%;
248
+ }
249
+ &:nth-child(4) {
250
+ width: 20%;
251
+ border-right: 1px solid transparent;
252
+ }
253
+ &:hover {
254
+ .keybinding_optional_actions {
255
+ display: flex;
256
+ }
257
+ }
258
+ }
259
+ .keybinding_command {
260
+ display: flex;
261
+ flex-direction: column;
262
+ justify-content: flex-start;
263
+ align-items: center;
264
+ }
265
+
266
+ .limit_warp {
267
+ font-size: 13px;
268
+ overflow: hidden;
269
+ text-overflow: ellipsis;
270
+ white-space: nowrap;
271
+ }
272
+
273
+ .command_name {
274
+ height: 20px;
275
+ font-size: 13px;
276
+ line-height: 20px;
277
+ text-align: left;
278
+ overflow: hidden;
279
+ text-overflow: ellipsis;
280
+ white-space: nowrap;
281
+ width: 100%;
282
+ margin-top: 2px;
283
+ }
284
+
285
+ .command_id {
286
+ height: 16px;
287
+ line-height: 16px;
288
+ text-align: left;
289
+ overflow: hidden;
290
+ text-overflow: ellipsis;
291
+ white-space: nowrap;
292
+ font-size: 12px;
293
+ opacity: 0.6;
294
+ width: 100%;
295
+ }
296
+
297
+ &.odd {
298
+ background-color: hsla(0, 0%, 51%, 0.04);
299
+ }
300
+
301
+ .keybinding_inline_action {
302
+ display: none;
303
+ height: 40px;
304
+ line-height: 40px;
305
+ width: 20px;
306
+ text-align: left;
307
+ text-align: center;
308
+ cursor: pointer;
309
+ &:hover {
310
+ transform: scale(1.1);
311
+ }
312
+ }
313
+
314
+ .keybinding_action {
315
+ display: none;
316
+ position: absolute;
317
+ right: 5px;
318
+ height: 40px;
319
+ line-height: 40px;
320
+ text-align: center;
321
+ z-index: 10;
322
+ cursor: pointer;
323
+ }
324
+
325
+ &:hover {
326
+ color: var(--list-hoverForeground);
327
+ background-color: var(--list-hoverBackground);
328
+
329
+ .keybinding_action,
330
+ .keybinding_inline_action {
331
+ display: inline-block;
332
+ }
333
+ }
334
+ }
335
+
336
+ .keybinding_header_item {
337
+ width: 25%;
338
+ border-left: 1px solid transparent;
339
+ box-sizing: border-box;
340
+ padding-left: 30px;
341
+ overflow: hidden;
342
+ text-overflow: ellipsis;
343
+ white-space: nowrap;
344
+ height: 40px;
345
+ line-height: 40px;
346
+ &:nth-child(1) {
347
+ width: 30%;
348
+ }
349
+ &:nth-child(4) {
350
+ width: 20%;
351
+ }
352
+ }
353
+
354
+ .search_container {
355
+ position: relative;
356
+ height: 100%;
357
+ width: 100%;
358
+ &:hover {
359
+ .keybinding_optional_actions {
360
+ display: flex;
361
+ }
362
+ }
363
+ }
364
+
365
+ .search_input {
366
+ height: 40px;
367
+ width: 100%;
368
+ }
369
+
370
+ .keybinding_optional_actions {
371
+ position: absolute;
372
+ right: 5px;
373
+ top: 0;
374
+ display: none;
375
+ align-items: center;
376
+ justify-content: center;
377
+ height: 100%;
378
+ .keybinding_optional_action {
379
+ cursor: pointer;
380
+ color: var(--inputicon-foreground);
381
+ display: block;
382
+ font-size: 14px;
383
+ width: 16px;
384
+ height: 16px;
385
+ line-height: 16px;
386
+ text-align: center;
387
+ }
388
+ }
389
+
390
+ .search_inline_action {
391
+ height: 100%;
392
+ padding: 0 5px;
393
+ line-height: 20px;
394
+ display: flex;
395
+ align-items: center;
396
+ justify-content: flex-start;
397
+ &_icon {
398
+ display: block;
399
+ height: 18px;
400
+ width: 18px;
401
+ text-align: center;
402
+ box-sizing: content-box;
403
+ border: 1px solid transparent;
404
+ cursor: pointer;
405
+ &.active {
406
+ border: 1px solid var(--focusBorder);
407
+ }
408
+ }
409
+ }