diff --git a/packages/cursorless-engine/src/processTargets/targets/PositionTarget.ts b/packages/cursorless-engine/src/processTargets/targets/PositionTarget.ts index a0180b078e..c25e91be73 100644 --- a/packages/cursorless-engine/src/processTargets/targets/PositionTarget.ts +++ b/packages/cursorless-engine/src/processTargets/targets/PositionTarget.ts @@ -44,8 +44,15 @@ export default class PositionTarget extends BaseTarget { if ( this.insertionDelimiter === "\n" && this.position === "after" && - this.thatTarget.contentRange.isSingleLine + this.state.thatTarget!.contentRange.isSingleLine ) { + // If the target that we're wrapping is not a single line, then we + // want to compute indentation based on the entire target. Otherwise, + // we allow the editor to determine how to perform indentation. + // Note that we use `this.state.thatTarget` rather than `this.thatTarget` + // because we don't really want the transitive `thatTarget` behaviour, as + // it's not really the "that" target that we're after; it's the target that + // we're wrapping. Should rework this stuff as part of #803. return "insertLineAfter"; } diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/cursorless-snippets/elseBranch.cursorless-snippets b/packages/cursorless-vscode-e2e/src/suite/fixtures/cursorless-snippets/elseBranch.cursorless-snippets new file mode 100644 index 0000000000..e5e0e3c56d --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/cursorless-snippets/elseBranch.cursorless-snippets @@ -0,0 +1,22 @@ +{ + "elseStatement": { + "definitions": [ + { + "scope": { + "langIds": [ + "python" + ] + }, + "body": [ + "else:", + "\t$body" + ] + } + ], + "description": "Else branch", + "variables": { + "body": {} + }, + "insertionScopeTypes": ["branch"] + } +} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/positions/snipElseAfterThis.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/positions/snipElseAfterThis.yml new file mode 100644 index 0000000000..755a0a533e --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/positions/snipElseAfterThis.yml @@ -0,0 +1,31 @@ +languageId: python +command: + version: 5 + spokenForm: snip else after this + action: + name: insertSnippet + args: + - {type: named, name: elseStatement} + targets: + - type: primitive + mark: {type: cursor} + modifiers: + - {type: position, position: after} + usePrePhraseSnapshot: true +initialState: + documentContents: | + if True: + aaa = "bbb" + selections: + - anchor: {line: 1, character: 7} + active: {line: 1, character: 7} + marks: {} +finalState: + documentContents: | + if True: + aaa = "bbb" + else: + + selections: + - anchor: {line: 3, character: 4} + active: {line: 3, character: 4}