Fix single line if/else and loop indentation

This commit is contained in:
Stephen Sigwart 2021-11-06 12:02:54 -04:00
parent 66b1668b66
commit d021de11ab
2 changed files with 16 additions and 0 deletions

View file

@ -76,6 +76,15 @@
"indent": "none",
"removeText": 1
}
},
{
// Decrease indentation after single line if/else if/else, for, foreach, or while
"previousLineText": "^\\s*(((else ?)?if|for(each)?|while)\\s*\\(.*\\)\\s*|else\\s*)$",
// But make sure line doesn't have braces or is not another if statement
"beforeText": "^\\s+([^{i\\s]|i(?!f\\b))",
"action": {
"indent": "outdent"
}
}
]
}

View file

@ -49,6 +49,13 @@ const jsTsLanguageConfiguration: vscode.LanguageConfiguration = {
beforeText: /^\s*(\bcase\s.+:|\bdefault:)$/,
afterText: /^(?!\s*(\bcase\b|\bdefault\b))/,
action: { indentAction: vscode.IndentAction.Indent },
},
{
// Decrease indentation after single line if/else if/else, for, or while
previousLineText: /^\s*(((else )?if|for|while)\s*\(.*\)\s*|else\s*)$/,
// But make sure line doesn't have braces or is not another if statement
beforeText: /^\s+([^{i\s]|i(?!f\b))/,
action: { indentAction: vscode.IndentAction.Outdent },
}
]
};