Skip to content

Commit 38e1619

Browse files
authored
Fix Cursorless keyboard broken by focused elements (#25)
This was not caught by our tests because we mock away command server. Not sure how to prevent this sort of thing in the future
1 parent e75028b commit 38e1619

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@
4747
{
4848
"command": "command-server.runCommand",
4949
"key": "ctrl+shift+f17",
50-
"mac": "cmd+shift+f17"
50+
"mac": "cmd+shift+f17",
51+
"args": "other"
5152
},
5253
{
5354
"command": "command-server.runCommand",
5455
"key": "ctrl+shift+alt+p",
55-
"mac": "cmd+shift+alt+p"
56+
"mac": "cmd+shift+alt+p",
57+
"args": "other"
5658
},
5759
{
5860
"command": "command-server.runCommand",

src/commandRunner.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ export default class CommandRunner {
6565

6666
const warnings = [];
6767

68+
let commandPromise: Thenable<unknown> | undefined;
69+
6870
try {
6971
if (!vscode.window.state.focused) {
7072
if (this.backgroundWindowProtection) {
@@ -82,7 +84,7 @@ export default class CommandRunner {
8284
throw new Error("Command in denyList");
8385
}
8486

85-
const commandPromise = vscode.commands.executeCommand(commandId, ...args);
87+
commandPromise = vscode.commands.executeCommand(commandId, ...args);
8688

8789
let commandReturnValue = null;
8890

@@ -107,5 +109,9 @@ export default class CommandRunner {
107109
}
108110

109111
await this.io.closeResponse();
112+
113+
if (commandPromise != null) {
114+
await commandPromise;
115+
}
110116
}
111117
}

src/extension.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ export async function activate(context: vscode.ExtensionContext) {
1414
context.subscriptions.push(
1515
vscode.commands.registerCommand(
1616
"command-server.runCommand",
17-
(focusedElementType_?: FocusedElementType) => {
17+
async (focusedElementType_: FocusedElementType) => {
1818
focusedElementType = focusedElementType_;
19-
return commandRunner.runCommand();
19+
await commandRunner.runCommand();
20+
focusedElementType = undefined;
2021
}
2122
),
2223
vscode.commands.registerCommand(
2324
"command-server.getFocusedElementType",
24-
() => focusedElementType ?? null
25+
() => focusedElementType
2526
)
2627
);
2728

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ export interface Response {
5555
/**
5656
* The type of the focused element in vscode at the moment of the command being executed.
5757
*/
58-
export type FocusedElementType = "textEditor" | "terminal";
58+
export type FocusedElementType = "textEditor" | "terminal" | "other";

0 commit comments

Comments
 (0)