forked from irinazheltisheva/vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickaccess.ts
More file actions
81 lines (63 loc) · 2.32 KB
/
quickaccess.ts
File metadata and controls
81 lines (63 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Editors } from './editors';
import { Code } from './code';
import { QuickInput } from './quickinput';
export class QuickAccess {
constructor(private code: Code, private editors: Editors, private quickInput: QuickInput) { }
async openQuickAccess(value: string): Promise<void> {
let retries = 0;
// other parts of code might steal focus away from quickinput :(
while (retries < 5) {
if (process.platform === 'darwin') {
await this.code.dispatchKeybinding('cmd+p');
} else {
await this.code.dispatchKeybinding('ctrl+p');
}
try {
await this.quickInput.waitForQuickInputOpened(10);
break;
} catch (err) {
if (++retries > 5) {
throw err;
}
await this.code.dispatchKeybinding('escape');
}
}
if (value) {
await this.code.waitForSetValue(QuickInput.QUICK_INPUT_INPUT, value);
}
}
async openFile(fileName: string): Promise<void> {
await this.openQuickAccess(fileName);
await this.quickInput.waitForQuickInputElements(names => names[0] === fileName);
await this.code.dispatchKeybinding('enter');
await this.editors.waitForActiveTab(fileName);
await this.editors.waitForEditorFocus(fileName);
}
async runCommand(commandId: string): Promise<void> {
await this.openQuickAccess(`>${commandId}`);
// wait for best choice to be focused
await this.code.waitForTextContent(QuickInput.QUICK_INPUT_FOCUSED_ELEMENT);
// wait and click on best choice
await this.quickInput.selectQuickInputElement(0);
}
async openQuickOutline(): Promise<void> {
let retries = 0;
while (++retries < 10) {
if (process.platform === 'darwin') {
await this.code.dispatchKeybinding('cmd+shift+o');
} else {
await this.code.dispatchKeybinding('ctrl+shift+o');
}
const text = await this.code.waitForTextContent(QuickInput.QUICK_INPUT_ENTRY_LABEL_SPAN);
if (text !== 'No symbol information for the file') {
return;
}
await this.quickInput.closeQuickInput();
await new Promise(c => setTimeout(c, 250));
}
}
}