@theia/api-tests 1.34.2 → 1.34.3
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/LICENSE +641 -641
- package/package.json +3 -3
- package/src/api-tests.d.ts +21 -21
- package/src/browser-utils.spec.js +53 -53
- package/src/contribution-filter.spec.js +36 -36
- package/src/file-search.spec.js +132 -132
- package/src/find-replace.spec.js +129 -129
- package/src/keybindings.spec.js +117 -117
- package/src/launch-preferences.spec.js +697 -697
- package/src/menus.spec.js +176 -176
- package/src/monaco-api.spec.js +188 -188
- package/src/navigator.spec.js +92 -92
- package/src/preferences.spec.js +207 -207
- package/src/saveable.spec.js +503 -503
- package/src/scm.spec.js +173 -173
- package/src/shell.spec.js +41 -41
- package/src/task-configurations.spec.js +112 -112
- package/src/typescript.spec.js +779 -779
- package/src/undo-redo-selectAll.spec.js +193 -193
- package/src/views.spec.js +76 -76
package/src/find-replace.spec.js
CHANGED
|
@@ -1,129 +1,129 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2020 TypeFox and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
// @ts-check
|
|
18
|
-
describe('Find and Replace', function () {
|
|
19
|
-
|
|
20
|
-
const { assert } = chai;
|
|
21
|
-
|
|
22
|
-
const { animationFrame } = require('@theia/core/lib/browser/browser');
|
|
23
|
-
const { DisposableCollection } = require('@theia/core/lib/common/disposable');
|
|
24
|
-
const { CommonCommands } = require('@theia/core/lib/browser/common-frontend-contribution');
|
|
25
|
-
const { EditorManager } = require('@theia/editor/lib/browser/editor-manager');
|
|
26
|
-
const { WorkspaceService } = require('@theia/workspace/lib/browser/workspace-service');
|
|
27
|
-
const { CommandRegistry } = require('@theia/core/lib/common/command');
|
|
28
|
-
const { KeybindingRegistry } = require('@theia/core/lib/browser/keybinding');
|
|
29
|
-
const { ContextKeyService } = require('@theia/core/lib/browser/context-key-service');
|
|
30
|
-
const { FileNavigatorContribution } = require('@theia/navigator/lib/browser/navigator-contribution');
|
|
31
|
-
const { ApplicationShell } = require('@theia/core/lib/browser/shell/application-shell');
|
|
32
|
-
|
|
33
|
-
const container = window.theia.container;
|
|
34
|
-
const editorManager = container.get(EditorManager);
|
|
35
|
-
const workspaceService = container.get(WorkspaceService);
|
|
36
|
-
const commands = container.get(CommandRegistry);
|
|
37
|
-
const keybindings = container.get(KeybindingRegistry);
|
|
38
|
-
const contextKeyService = container.get(ContextKeyService);
|
|
39
|
-
const navigatorContribution = container.get(FileNavigatorContribution);
|
|
40
|
-
const shell = container.get(ApplicationShell);
|
|
41
|
-
|
|
42
|
-
const rootUri = workspaceService.tryGetRoots()[0].resource;
|
|
43
|
-
const fileUri = rootUri.resolve('webpack.config.js');
|
|
44
|
-
|
|
45
|
-
const toTearDown = new DisposableCollection();
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @template T
|
|
49
|
-
* @param {() => Promise<T> | T} condition
|
|
50
|
-
* @returns {Promise<T>}
|
|
51
|
-
*/
|
|
52
|
-
function waitForAnimation(condition) {
|
|
53
|
-
return new Promise(async (resolve, dispose) => {
|
|
54
|
-
toTearDown.push({ dispose });
|
|
55
|
-
do {
|
|
56
|
-
await animationFrame();
|
|
57
|
-
} while (!condition());
|
|
58
|
-
resolve();
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
before(() => {
|
|
63
|
-
shell.leftPanelHandler.collapse();
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
beforeEach(async function () {
|
|
67
|
-
await navigatorContribution.closeView();
|
|
68
|
-
await editorManager.closeAll({ save: false });
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
afterEach(async () => {
|
|
72
|
-
toTearDown.dispose();
|
|
73
|
-
await navigatorContribution.closeView();
|
|
74
|
-
await editorManager.closeAll({ save: false });
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
after(() => {
|
|
78
|
-
shell.leftPanelHandler.collapse();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* @param {import('@theia/core/lib/common/command').Command} command
|
|
83
|
-
*/
|
|
84
|
-
async function assertEditorFindReplace(command) {
|
|
85
|
-
assert.isFalse(contextKeyService.match('findWidgetVisible'));
|
|
86
|
-
assert.isFalse(contextKeyService.match('findInputFocussed'));
|
|
87
|
-
assert.isFalse(contextKeyService.match('replaceInputFocussed'));
|
|
88
|
-
|
|
89
|
-
keybindings.dispatchCommand(command.id);
|
|
90
|
-
await waitForAnimation(() => contextKeyService.match('findInputFocussed'));
|
|
91
|
-
|
|
92
|
-
assert.isTrue(contextKeyService.match('findWidgetVisible'));
|
|
93
|
-
assert.isTrue(contextKeyService.match('findInputFocussed'));
|
|
94
|
-
assert.isFalse(contextKeyService.match('replaceInputFocussed'));
|
|
95
|
-
|
|
96
|
-
keybindings.dispatchKeyDown('Tab');
|
|
97
|
-
await waitForAnimation(() => !contextKeyService.match('findInputFocussed'));
|
|
98
|
-
assert.isTrue(contextKeyService.match('findWidgetVisible'));
|
|
99
|
-
assert.isFalse(contextKeyService.match('findInputFocussed'));
|
|
100
|
-
assert.equal(contextKeyService.match('replaceInputFocussed'), command === CommonCommands.REPLACE);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
for (const command of [CommonCommands.FIND, CommonCommands.REPLACE]) {
|
|
104
|
-
it(command.label + ' in the active editor', async function () {
|
|
105
|
-
await navigatorContribution.openView({ activate: true });
|
|
106
|
-
|
|
107
|
-
await editorManager.open(fileUri, { mode: 'activate' });
|
|
108
|
-
|
|
109
|
-
await assertEditorFindReplace(command);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it(command.label + ' in the active explorer without the current editor', async function () {
|
|
113
|
-
await navigatorContribution.openView({ activate: true });
|
|
114
|
-
|
|
115
|
-
// should not throw
|
|
116
|
-
await commands.executeCommand(command.id);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it(command.label + ' in the active explorer with the current editor', async function () {
|
|
120
|
-
await editorManager.open(fileUri, { mode: 'activate' });
|
|
121
|
-
|
|
122
|
-
await navigatorContribution.openView({ activate: true });
|
|
123
|
-
|
|
124
|
-
await assertEditorFindReplace(command);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
});
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2020 TypeFox and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
// @ts-check
|
|
18
|
+
describe('Find and Replace', function () {
|
|
19
|
+
|
|
20
|
+
const { assert } = chai;
|
|
21
|
+
|
|
22
|
+
const { animationFrame } = require('@theia/core/lib/browser/browser');
|
|
23
|
+
const { DisposableCollection } = require('@theia/core/lib/common/disposable');
|
|
24
|
+
const { CommonCommands } = require('@theia/core/lib/browser/common-frontend-contribution');
|
|
25
|
+
const { EditorManager } = require('@theia/editor/lib/browser/editor-manager');
|
|
26
|
+
const { WorkspaceService } = require('@theia/workspace/lib/browser/workspace-service');
|
|
27
|
+
const { CommandRegistry } = require('@theia/core/lib/common/command');
|
|
28
|
+
const { KeybindingRegistry } = require('@theia/core/lib/browser/keybinding');
|
|
29
|
+
const { ContextKeyService } = require('@theia/core/lib/browser/context-key-service');
|
|
30
|
+
const { FileNavigatorContribution } = require('@theia/navigator/lib/browser/navigator-contribution');
|
|
31
|
+
const { ApplicationShell } = require('@theia/core/lib/browser/shell/application-shell');
|
|
32
|
+
|
|
33
|
+
const container = window.theia.container;
|
|
34
|
+
const editorManager = container.get(EditorManager);
|
|
35
|
+
const workspaceService = container.get(WorkspaceService);
|
|
36
|
+
const commands = container.get(CommandRegistry);
|
|
37
|
+
const keybindings = container.get(KeybindingRegistry);
|
|
38
|
+
const contextKeyService = container.get(ContextKeyService);
|
|
39
|
+
const navigatorContribution = container.get(FileNavigatorContribution);
|
|
40
|
+
const shell = container.get(ApplicationShell);
|
|
41
|
+
|
|
42
|
+
const rootUri = workspaceService.tryGetRoots()[0].resource;
|
|
43
|
+
const fileUri = rootUri.resolve('webpack.config.js');
|
|
44
|
+
|
|
45
|
+
const toTearDown = new DisposableCollection();
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @template T
|
|
49
|
+
* @param {() => Promise<T> | T} condition
|
|
50
|
+
* @returns {Promise<T>}
|
|
51
|
+
*/
|
|
52
|
+
function waitForAnimation(condition) {
|
|
53
|
+
return new Promise(async (resolve, dispose) => {
|
|
54
|
+
toTearDown.push({ dispose });
|
|
55
|
+
do {
|
|
56
|
+
await animationFrame();
|
|
57
|
+
} while (!condition());
|
|
58
|
+
resolve();
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
before(() => {
|
|
63
|
+
shell.leftPanelHandler.collapse();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
beforeEach(async function () {
|
|
67
|
+
await navigatorContribution.closeView();
|
|
68
|
+
await editorManager.closeAll({ save: false });
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
afterEach(async () => {
|
|
72
|
+
toTearDown.dispose();
|
|
73
|
+
await navigatorContribution.closeView();
|
|
74
|
+
await editorManager.closeAll({ save: false });
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
after(() => {
|
|
78
|
+
shell.leftPanelHandler.collapse();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @param {import('@theia/core/lib/common/command').Command} command
|
|
83
|
+
*/
|
|
84
|
+
async function assertEditorFindReplace(command) {
|
|
85
|
+
assert.isFalse(contextKeyService.match('findWidgetVisible'));
|
|
86
|
+
assert.isFalse(contextKeyService.match('findInputFocussed'));
|
|
87
|
+
assert.isFalse(contextKeyService.match('replaceInputFocussed'));
|
|
88
|
+
|
|
89
|
+
keybindings.dispatchCommand(command.id);
|
|
90
|
+
await waitForAnimation(() => contextKeyService.match('findInputFocussed'));
|
|
91
|
+
|
|
92
|
+
assert.isTrue(contextKeyService.match('findWidgetVisible'));
|
|
93
|
+
assert.isTrue(contextKeyService.match('findInputFocussed'));
|
|
94
|
+
assert.isFalse(contextKeyService.match('replaceInputFocussed'));
|
|
95
|
+
|
|
96
|
+
keybindings.dispatchKeyDown('Tab');
|
|
97
|
+
await waitForAnimation(() => !contextKeyService.match('findInputFocussed'));
|
|
98
|
+
assert.isTrue(contextKeyService.match('findWidgetVisible'));
|
|
99
|
+
assert.isFalse(contextKeyService.match('findInputFocussed'));
|
|
100
|
+
assert.equal(contextKeyService.match('replaceInputFocussed'), command === CommonCommands.REPLACE);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
for (const command of [CommonCommands.FIND, CommonCommands.REPLACE]) {
|
|
104
|
+
it(command.label + ' in the active editor', async function () {
|
|
105
|
+
await navigatorContribution.openView({ activate: true });
|
|
106
|
+
|
|
107
|
+
await editorManager.open(fileUri, { mode: 'activate' });
|
|
108
|
+
|
|
109
|
+
await assertEditorFindReplace(command);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it(command.label + ' in the active explorer without the current editor', async function () {
|
|
113
|
+
await navigatorContribution.openView({ activate: true });
|
|
114
|
+
|
|
115
|
+
// should not throw
|
|
116
|
+
await commands.executeCommand(command.id);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it(command.label + ' in the active explorer with the current editor', async function () {
|
|
120
|
+
await editorManager.open(fileUri, { mode: 'activate' });
|
|
121
|
+
|
|
122
|
+
await navigatorContribution.openView({ activate: true });
|
|
123
|
+
|
|
124
|
+
await assertEditorFindReplace(command);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
});
|
package/src/keybindings.spec.js
CHANGED
|
@@ -1,117 +1,117 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2020 TypeFox and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
// @ts-check
|
|
18
|
-
describe('Keybindings', function () {
|
|
19
|
-
|
|
20
|
-
const { assert } = chai;
|
|
21
|
-
|
|
22
|
-
const { Disposable, DisposableCollection } = require('@theia/core/lib/common/disposable');
|
|
23
|
-
const { isOSX } = require('@theia/core/lib/common/os');
|
|
24
|
-
const { CommonCommands } = require('@theia/core/lib/browser/common-frontend-contribution');
|
|
25
|
-
const { TerminalService } = require('@theia/terminal/lib/browser/base/terminal-service');
|
|
26
|
-
const { TerminalCommands } = require('@theia/terminal/lib/browser/terminal-frontend-contribution');
|
|
27
|
-
const { ApplicationShell } = require('@theia/core/lib/browser/shell/application-shell');
|
|
28
|
-
const { KeybindingRegistry } = require('@theia/core/lib/browser/keybinding');
|
|
29
|
-
const { CommandRegistry } = require('@theia/core/lib/common/command');
|
|
30
|
-
const { Deferred } = require('@theia/core/lib/common/promise-util');
|
|
31
|
-
const { Key } = require('@theia/core/lib/browser/keys');
|
|
32
|
-
const { EditorManager } = require('@theia/editor/lib/browser/editor-manager');
|
|
33
|
-
const { WorkspaceService } = require('@theia/workspace/lib/browser/workspace-service');
|
|
34
|
-
|
|
35
|
-
/** @type {import('inversify').Container} */
|
|
36
|
-
const container = window['theia'].container;
|
|
37
|
-
/** @type {import('@theia/terminal/lib/browser/base/terminal-service').TerminalService} */
|
|
38
|
-
const terminalService = container.get(TerminalService);
|
|
39
|
-
const applicationShell = container.get(ApplicationShell);
|
|
40
|
-
const keybindings = container.get(KeybindingRegistry);
|
|
41
|
-
const commands = container.get(CommandRegistry);
|
|
42
|
-
const editorManager = container.get(EditorManager);
|
|
43
|
-
const workspaceService = container.get(WorkspaceService);
|
|
44
|
-
|
|
45
|
-
const toTearDown = new DisposableCollection();
|
|
46
|
-
afterEach(() => toTearDown.dispose());
|
|
47
|
-
|
|
48
|
-
it('partial keybinding should not override full in the same scope', async () => {
|
|
49
|
-
const terminal = /** @type {import('@theia/terminal/lib/browser/terminal-widget-impl').TerminalWidgetImpl} */
|
|
50
|
-
(await terminalService.newTerminal({}));
|
|
51
|
-
toTearDown.push(Disposable.create(() => terminal.dispose()));
|
|
52
|
-
terminalService.open(terminal, { mode: 'activate' });
|
|
53
|
-
await applicationShell.waitForActivation(terminal.id);
|
|
54
|
-
const waitForCommand = new Deferred();
|
|
55
|
-
toTearDown.push(commands.onWillExecuteCommand(e => waitForCommand.resolve(e.commandId)));
|
|
56
|
-
keybindings.dispatchKeyDown({
|
|
57
|
-
code: Key.KEY_K.code,
|
|
58
|
-
metaKey: isOSX,
|
|
59
|
-
ctrlKey: !isOSX
|
|
60
|
-
}, terminal.node);
|
|
61
|
-
const executedCommand = await waitForCommand.promise;
|
|
62
|
-
assert.equal(executedCommand, TerminalCommands.TERMINAL_CLEAR.id);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('disabled keybinding should not override enabled', async () => {
|
|
66
|
-
const id = '__test:keybindings.left';
|
|
67
|
-
toTearDown.push(commands.registerCommand({ id }, {
|
|
68
|
-
execute: () => { }
|
|
69
|
-
}));
|
|
70
|
-
toTearDown.push(keybindings.registerKeybinding({
|
|
71
|
-
command: id,
|
|
72
|
-
keybinding: 'left',
|
|
73
|
-
when: 'false'
|
|
74
|
-
}));
|
|
75
|
-
|
|
76
|
-
const editor = await editorManager.open(workspaceService.tryGetRoots()[0].resource.resolve('package.json'), {
|
|
77
|
-
mode: 'activate',
|
|
78
|
-
selection: {
|
|
79
|
-
start: {
|
|
80
|
-
line: 0,
|
|
81
|
-
character: 1
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
toTearDown.push(editor);
|
|
86
|
-
|
|
87
|
-
const waitForCommand = new Deferred();
|
|
88
|
-
toTearDown.push(commands.onWillExecuteCommand(e => waitForCommand.resolve(e.commandId)));
|
|
89
|
-
keybindings.dispatchKeyDown({
|
|
90
|
-
code: Key.ARROW_LEFT.code
|
|
91
|
-
}, editor.node);
|
|
92
|
-
const executedCommand = await waitForCommand.promise;
|
|
93
|
-
assert.notEqual(executedCommand, id);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('later registered keybinding should have higher priority', async () => {
|
|
97
|
-
const id = '__test:keybindings.copy';
|
|
98
|
-
toTearDown.push(commands.registerCommand({ id }, {
|
|
99
|
-
execute: () => { }
|
|
100
|
-
}));
|
|
101
|
-
const keybinding = keybindings.getKeybindingsForCommand(CommonCommands.COPY.id)[0];
|
|
102
|
-
toTearDown.push(keybindings.registerKeybinding({
|
|
103
|
-
command: id,
|
|
104
|
-
keybinding: keybinding.keybinding
|
|
105
|
-
}));
|
|
106
|
-
const waitForCommand = new Deferred();
|
|
107
|
-
toTearDown.push(commands.onWillExecuteCommand(e => waitForCommand.resolve(e.commandId)));
|
|
108
|
-
keybindings.dispatchKeyDown({
|
|
109
|
-
code: Key.KEY_C.code,
|
|
110
|
-
metaKey: isOSX,
|
|
111
|
-
ctrlKey: !isOSX
|
|
112
|
-
});
|
|
113
|
-
const executedCommand = await waitForCommand.promise;
|
|
114
|
-
assert.equal(executedCommand, id);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
});
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2020 TypeFox and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
// @ts-check
|
|
18
|
+
describe('Keybindings', function () {
|
|
19
|
+
|
|
20
|
+
const { assert } = chai;
|
|
21
|
+
|
|
22
|
+
const { Disposable, DisposableCollection } = require('@theia/core/lib/common/disposable');
|
|
23
|
+
const { isOSX } = require('@theia/core/lib/common/os');
|
|
24
|
+
const { CommonCommands } = require('@theia/core/lib/browser/common-frontend-contribution');
|
|
25
|
+
const { TerminalService } = require('@theia/terminal/lib/browser/base/terminal-service');
|
|
26
|
+
const { TerminalCommands } = require('@theia/terminal/lib/browser/terminal-frontend-contribution');
|
|
27
|
+
const { ApplicationShell } = require('@theia/core/lib/browser/shell/application-shell');
|
|
28
|
+
const { KeybindingRegistry } = require('@theia/core/lib/browser/keybinding');
|
|
29
|
+
const { CommandRegistry } = require('@theia/core/lib/common/command');
|
|
30
|
+
const { Deferred } = require('@theia/core/lib/common/promise-util');
|
|
31
|
+
const { Key } = require('@theia/core/lib/browser/keys');
|
|
32
|
+
const { EditorManager } = require('@theia/editor/lib/browser/editor-manager');
|
|
33
|
+
const { WorkspaceService } = require('@theia/workspace/lib/browser/workspace-service');
|
|
34
|
+
|
|
35
|
+
/** @type {import('inversify').Container} */
|
|
36
|
+
const container = window['theia'].container;
|
|
37
|
+
/** @type {import('@theia/terminal/lib/browser/base/terminal-service').TerminalService} */
|
|
38
|
+
const terminalService = container.get(TerminalService);
|
|
39
|
+
const applicationShell = container.get(ApplicationShell);
|
|
40
|
+
const keybindings = container.get(KeybindingRegistry);
|
|
41
|
+
const commands = container.get(CommandRegistry);
|
|
42
|
+
const editorManager = container.get(EditorManager);
|
|
43
|
+
const workspaceService = container.get(WorkspaceService);
|
|
44
|
+
|
|
45
|
+
const toTearDown = new DisposableCollection();
|
|
46
|
+
afterEach(() => toTearDown.dispose());
|
|
47
|
+
|
|
48
|
+
it('partial keybinding should not override full in the same scope', async () => {
|
|
49
|
+
const terminal = /** @type {import('@theia/terminal/lib/browser/terminal-widget-impl').TerminalWidgetImpl} */
|
|
50
|
+
(await terminalService.newTerminal({}));
|
|
51
|
+
toTearDown.push(Disposable.create(() => terminal.dispose()));
|
|
52
|
+
terminalService.open(terminal, { mode: 'activate' });
|
|
53
|
+
await applicationShell.waitForActivation(terminal.id);
|
|
54
|
+
const waitForCommand = new Deferred();
|
|
55
|
+
toTearDown.push(commands.onWillExecuteCommand(e => waitForCommand.resolve(e.commandId)));
|
|
56
|
+
keybindings.dispatchKeyDown({
|
|
57
|
+
code: Key.KEY_K.code,
|
|
58
|
+
metaKey: isOSX,
|
|
59
|
+
ctrlKey: !isOSX
|
|
60
|
+
}, terminal.node);
|
|
61
|
+
const executedCommand = await waitForCommand.promise;
|
|
62
|
+
assert.equal(executedCommand, TerminalCommands.TERMINAL_CLEAR.id);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('disabled keybinding should not override enabled', async () => {
|
|
66
|
+
const id = '__test:keybindings.left';
|
|
67
|
+
toTearDown.push(commands.registerCommand({ id }, {
|
|
68
|
+
execute: () => { }
|
|
69
|
+
}));
|
|
70
|
+
toTearDown.push(keybindings.registerKeybinding({
|
|
71
|
+
command: id,
|
|
72
|
+
keybinding: 'left',
|
|
73
|
+
when: 'false'
|
|
74
|
+
}));
|
|
75
|
+
|
|
76
|
+
const editor = await editorManager.open(workspaceService.tryGetRoots()[0].resource.resolve('package.json'), {
|
|
77
|
+
mode: 'activate',
|
|
78
|
+
selection: {
|
|
79
|
+
start: {
|
|
80
|
+
line: 0,
|
|
81
|
+
character: 1
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
toTearDown.push(editor);
|
|
86
|
+
|
|
87
|
+
const waitForCommand = new Deferred();
|
|
88
|
+
toTearDown.push(commands.onWillExecuteCommand(e => waitForCommand.resolve(e.commandId)));
|
|
89
|
+
keybindings.dispatchKeyDown({
|
|
90
|
+
code: Key.ARROW_LEFT.code
|
|
91
|
+
}, editor.node);
|
|
92
|
+
const executedCommand = await waitForCommand.promise;
|
|
93
|
+
assert.notEqual(executedCommand, id);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('later registered keybinding should have higher priority', async () => {
|
|
97
|
+
const id = '__test:keybindings.copy';
|
|
98
|
+
toTearDown.push(commands.registerCommand({ id }, {
|
|
99
|
+
execute: () => { }
|
|
100
|
+
}));
|
|
101
|
+
const keybinding = keybindings.getKeybindingsForCommand(CommonCommands.COPY.id)[0];
|
|
102
|
+
toTearDown.push(keybindings.registerKeybinding({
|
|
103
|
+
command: id,
|
|
104
|
+
keybinding: keybinding.keybinding
|
|
105
|
+
}));
|
|
106
|
+
const waitForCommand = new Deferred();
|
|
107
|
+
toTearDown.push(commands.onWillExecuteCommand(e => waitForCommand.resolve(e.commandId)));
|
|
108
|
+
keybindings.dispatchKeyDown({
|
|
109
|
+
code: Key.KEY_C.code,
|
|
110
|
+
metaKey: isOSX,
|
|
111
|
+
ctrlKey: !isOSX
|
|
112
|
+
});
|
|
113
|
+
const executedCommand = await waitForCommand.promise;
|
|
114
|
+
assert.equal(executedCommand, id);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
});
|