diff --git a/data/fixtures/recorded/fallback/takeToken2.yml b/data/fixtures/recorded/fallback/takeToken2.yml new file mode 100644 index 00000000000..bdcb9f8ce80 --- /dev/null +++ b/data/fixtures/recorded/fallback/takeToken2.yml @@ -0,0 +1,24 @@ +languageId: plaintext +focusedElementType: textEditor +command: + version: 7 + spokenForm: take token + action: + name: setSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: token} + usePrePhraseSnapshot: true +initialState: + documentContents: foo + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} + marks: {} +finalState: + documentContents: foo + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 3} diff --git a/packages/common/src/FakeCommandServerApi.ts b/packages/common/src/FakeCommandServerApi.ts index 8a96f445275..8ea7b910092 100644 --- a/packages/common/src/FakeCommandServerApi.ts +++ b/packages/common/src/FakeCommandServerApi.ts @@ -10,7 +10,6 @@ export class FakeCommandServerApi implements CommandServerApi { constructor() { this.signals = { prePhrase: { getVersion: async () => null } }; - this.focusedElementType = "textEditor"; } async getFocusedElementType(): Promise { diff --git a/packages/common/src/types/CommandServerApi.ts b/packages/common/src/types/CommandServerApi.ts index 96f1ecb3aec..0d3fdaa890e 100644 --- a/packages/common/src/types/CommandServerApi.ts +++ b/packages/common/src/types/CommandServerApi.ts @@ -9,7 +9,7 @@ export interface CommandServerApi { }; } -export type FocusedElementType = "textEditor" | "terminal"; +export type FocusedElementType = "textEditor" | "terminal" | "other"; export interface InboundSignal { getVersion(): Promise; diff --git a/packages/common/src/types/TestCaseFixture.ts b/packages/common/src/types/TestCaseFixture.ts index 7b366e694ae..c3030e2b401 100644 --- a/packages/common/src/types/TestCaseFixture.ts +++ b/packages/common/src/types/TestCaseFixture.ts @@ -15,7 +15,7 @@ interface TestCaseFixtureBase { /** * The type of element that is focused before the command is executed. If undefined default to text editor. */ - focusedElementType?: FocusedElementType | "other"; + focusedElementType?: FocusedElementType; /** * A list of marks to check in the case of navigation map test otherwise undefined diff --git a/packages/cursorless-engine/src/core/getCommandFallback.ts b/packages/cursorless-engine/src/core/getCommandFallback.ts index d69a4b86dc5..941a02c0eb3 100644 --- a/packages/cursorless-engine/src/core/getCommandFallback.ts +++ b/packages/cursorless-engine/src/core/getCommandFallback.ts @@ -14,10 +14,9 @@ export async function getCommandFallback( runAction: (actionDescriptor: ActionDescriptor) => Promise, command: CommandComplete, ): Promise { - if ( - commandServerApi == null || - (await commandServerApi.getFocusedElementType()) === "textEditor" - ) { + const focusedElementType = await commandServerApi?.getFocusedElementType(); + + if (focusedElementType == null || focusedElementType === "textEditor") { return null; } diff --git a/packages/cursorless-engine/src/testCaseRecorder/TestCase.ts b/packages/cursorless-engine/src/testCaseRecorder/TestCase.ts index 0dd2dad5329..2d4959b4966 100644 --- a/packages/cursorless-engine/src/testCaseRecorder/TestCase.ts +++ b/packages/cursorless-engine/src/testCaseRecorder/TestCase.ts @@ -141,9 +141,9 @@ export class TestCase { const fixture: EnforceUndefined = { languageId: this.languageId, focusedElementType: - this.focusedElementType !== "textEditor" - ? this.focusedElementType ?? "other" - : undefined, + this.focusedElementType === "textEditor" + ? undefined + : this.focusedElementType, postEditorOpenSleepTimeMs: undefined, postCommandSleepTimeMs: undefined, command: this.command, diff --git a/packages/cursorless-vscode-e2e/src/suite/recorded.vscode.test.ts b/packages/cursorless-vscode-e2e/src/suite/recorded.vscode.test.ts index 22258d170c2..5a759ce956e 100644 --- a/packages/cursorless-vscode-e2e/src/suite/recorded.vscode.test.ts +++ b/packages/cursorless-vscode-e2e/src/suite/recorded.vscode.test.ts @@ -104,11 +104,7 @@ async function runTest(file: string, spyIde: SpyIDE) { // spyIde.clipboard.writeText(fixture.initialState.clipboard); } - commandServerApi.setFocusedElementType( - fixture.focusedElementType === "other" - ? undefined - : fixture.focusedElementType ?? "textEditor", - ); + commandServerApi.setFocusedElementType(fixture.focusedElementType); // Ensure that the expected hats are present await hatTokenMap.allocateHats(