Skip to content

Fix snippet insertion indentation #1528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"elseStatement": {
"definitions": [
{
"scope": {
"langIds": [
"python"
]
},
"body": [
"else:",
"\t$body"
]
}
],
"description": "Else branch",
"variables": {
"body": {}
},
"insertionScopeTypes": ["branch"]
}
}
Original file line number Diff line number Diff line change
@@ -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}