@opensumi/ide-keymaps 2.21.8-rc-1670567192.0 → 2.21.8
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.
- package/package.json +10 -11
- package/src/browser/index.ts +0 -18
- package/src/browser/keymaps-parser.ts +0 -116
- package/src/browser/keymaps.contribution.ts +0 -202
- package/src/browser/keymaps.module.less +0 -409
- package/src/browser/keymaps.service.ts +0 -763
- package/src/browser/keymaps.view.tsx +0 -426
- package/src/common/const.ts +0 -3
- package/src/common/index.ts +0 -2
- package/src/common/keymaps.ts +0 -113
- package/src/index.ts +0 -1
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opensumi/ide-keymaps",
|
|
3
|
-
"version": "2.21.8
|
|
3
|
+
"version": "2.21.8",
|
|
4
4
|
"files": [
|
|
5
|
-
"lib"
|
|
6
|
-
"src"
|
|
5
|
+
"lib"
|
|
7
6
|
],
|
|
8
7
|
"license": "MIT",
|
|
9
8
|
"main": "lib/index.js",
|
|
@@ -17,16 +16,16 @@
|
|
|
17
16
|
"url": "git@github.com:opensumi/core.git"
|
|
18
17
|
},
|
|
19
18
|
"dependencies": {
|
|
20
|
-
"@opensumi/ide-core-common": "2.21.8
|
|
19
|
+
"@opensumi/ide-core-common": "2.21.8"
|
|
21
20
|
},
|
|
22
21
|
"devDependencies": {
|
|
23
|
-
"@opensumi/ide-components": "2.21.8
|
|
24
|
-
"@opensumi/ide-core-browser": "2.21.8
|
|
22
|
+
"@opensumi/ide-components": "2.21.8",
|
|
23
|
+
"@opensumi/ide-core-browser": "2.21.8",
|
|
25
24
|
"@opensumi/ide-dev-tool": "^1.3.1",
|
|
26
|
-
"@opensumi/ide-editor": "2.21.8
|
|
27
|
-
"@opensumi/ide-file-service": "2.21.8
|
|
28
|
-
"@opensumi/ide-preferences": "2.21.8
|
|
29
|
-
"@opensumi/ide-quick-open": "2.21.8
|
|
25
|
+
"@opensumi/ide-editor": "2.21.8",
|
|
26
|
+
"@opensumi/ide-file-service": "2.21.8",
|
|
27
|
+
"@opensumi/ide-preferences": "2.21.8",
|
|
28
|
+
"@opensumi/ide-quick-open": "2.21.8"
|
|
30
29
|
},
|
|
31
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "603eaa81756ee0e8a58871fb67cfb01c8499593a"
|
|
32
31
|
}
|
package/src/browser/index.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Provider, Injectable } from '@opensumi/di';
|
|
2
|
-
import { BrowserModule } from '@opensumi/ide-core-browser';
|
|
3
|
-
|
|
4
|
-
import { IKeymapService } from '../common';
|
|
5
|
-
|
|
6
|
-
import { KeymapsContribution } from './keymaps.contribution';
|
|
7
|
-
import { KeymapService } from './keymaps.service';
|
|
8
|
-
|
|
9
|
-
@Injectable()
|
|
10
|
-
export class KeymapsModule extends BrowserModule {
|
|
11
|
-
providers: Provider[] = [
|
|
12
|
-
{
|
|
13
|
-
token: IKeymapService,
|
|
14
|
-
useClass: KeymapService,
|
|
15
|
-
},
|
|
16
|
-
KeymapsContribution,
|
|
17
|
-
];
|
|
18
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import Ajv from 'ajv';
|
|
2
|
-
import * as parser from 'jsonc-parser';
|
|
3
|
-
|
|
4
|
-
import { Injectable } from '@opensumi/di';
|
|
5
|
-
|
|
6
|
-
import { KeymapItem } from '../common';
|
|
7
|
-
|
|
8
|
-
export const keymapsSchema = {
|
|
9
|
-
type: 'array',
|
|
10
|
-
items: {
|
|
11
|
-
type: 'object',
|
|
12
|
-
properties: {
|
|
13
|
-
// 为了兼容 vscode,优先使用 key
|
|
14
|
-
key: {
|
|
15
|
-
type: 'string',
|
|
16
|
-
},
|
|
17
|
-
keybinding: {
|
|
18
|
-
type: 'string',
|
|
19
|
-
deprecated: true,
|
|
20
|
-
},
|
|
21
|
-
command: {
|
|
22
|
-
type: 'string',
|
|
23
|
-
},
|
|
24
|
-
context: {
|
|
25
|
-
type: 'string',
|
|
26
|
-
},
|
|
27
|
-
when: {
|
|
28
|
-
type: 'string',
|
|
29
|
-
},
|
|
30
|
-
args: {},
|
|
31
|
-
},
|
|
32
|
-
required: ['command'],
|
|
33
|
-
optional: ['key', 'keybinding', 'when', 'args'],
|
|
34
|
-
additionalProperties: false,
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
@Injectable()
|
|
39
|
-
export class KeymapsParser {
|
|
40
|
-
protected readonly validate: Ajv.ValidateFunction;
|
|
41
|
-
|
|
42
|
-
constructor() {
|
|
43
|
-
// https://github.com/epoberezkin/ajv#validation-and-reporting-options
|
|
44
|
-
this.validate = new Ajv({
|
|
45
|
-
jsonPointers: true,
|
|
46
|
-
}).compile(keymapsSchema);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* 解析快捷键,存储潜在的错误
|
|
51
|
-
* @param content 内容.
|
|
52
|
-
* @param errors 可选的错误存储指针.
|
|
53
|
-
*/
|
|
54
|
-
parse(content: string, errors?: string[]): KeymapItem[] {
|
|
55
|
-
const strippedContent = parser.stripComments(content);
|
|
56
|
-
const parsingErrors: parser.ParseError[] | undefined = errors ? [] : undefined;
|
|
57
|
-
const bindings = parser.parse(strippedContent, parsingErrors);
|
|
58
|
-
if (parsingErrors && errors) {
|
|
59
|
-
for (const error of parsingErrors) {
|
|
60
|
-
errors.push(`${this.printParseErrorCode(error.error)} at ${error.offset} offset of ${error.length} length`);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (this.validate(bindings)) {
|
|
64
|
-
return bindings;
|
|
65
|
-
}
|
|
66
|
-
if (errors && this.validate.errors) {
|
|
67
|
-
for (const error of this.validate.errors) {
|
|
68
|
-
errors.push(`${error.message} at ${error.dataPath}`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return [];
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* 输出解析的错误代码
|
|
76
|
-
* @param code 错误码
|
|
77
|
-
*/
|
|
78
|
-
// https://github.com/Microsoft/node-jsonc-parser/issues/13
|
|
79
|
-
protected printParseErrorCode(code: number | undefined) {
|
|
80
|
-
switch (code) {
|
|
81
|
-
case parser.ParseErrorCode.InvalidSymbol:
|
|
82
|
-
return 'InvalidSymbol';
|
|
83
|
-
case parser.ParseErrorCode.InvalidNumberFormat:
|
|
84
|
-
return 'InvalidNumberFormat';
|
|
85
|
-
case parser.ParseErrorCode.PropertyNameExpected:
|
|
86
|
-
return 'PropertyNameExpected';
|
|
87
|
-
case parser.ParseErrorCode.ValueExpected:
|
|
88
|
-
return 'ValueExpected';
|
|
89
|
-
case parser.ParseErrorCode.ColonExpected:
|
|
90
|
-
return 'ColonExpected';
|
|
91
|
-
case parser.ParseErrorCode.CommaExpected:
|
|
92
|
-
return 'CommaExpected';
|
|
93
|
-
case parser.ParseErrorCode.CloseBraceExpected:
|
|
94
|
-
return 'CloseBraceExpected';
|
|
95
|
-
case parser.ParseErrorCode.CloseBracketExpected:
|
|
96
|
-
return 'CloseBracketExpected';
|
|
97
|
-
case parser.ParseErrorCode.EndOfFileExpected:
|
|
98
|
-
return 'EndOfFileExpected';
|
|
99
|
-
case parser.ParseErrorCode.InvalidCommentToken:
|
|
100
|
-
return 'InvalidCommentToken';
|
|
101
|
-
case parser.ParseErrorCode.UnexpectedEndOfComment:
|
|
102
|
-
return 'UnexpectedEndOfComment';
|
|
103
|
-
case parser.ParseErrorCode.UnexpectedEndOfString:
|
|
104
|
-
return 'UnexpectedEndOfString';
|
|
105
|
-
case parser.ParseErrorCode.UnexpectedEndOfNumber:
|
|
106
|
-
return 'UnexpectedEndOfNumber';
|
|
107
|
-
case parser.ParseErrorCode.InvalidUnicode:
|
|
108
|
-
return 'InvalidUnicode';
|
|
109
|
-
case parser.ParseErrorCode.InvalidEscapeCharacter:
|
|
110
|
-
return 'InvalidEscapeCharacter';
|
|
111
|
-
case parser.ParseErrorCode.InvalidCharacter:
|
|
112
|
-
return 'InvalidCharacter';
|
|
113
|
-
}
|
|
114
|
-
return '<unknown ParseErrorCode>';
|
|
115
|
-
}
|
|
116
|
-
}
|
|
@@ -1,202 +0,0 @@
|
|
|
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 } 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: '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
|
-
}
|