Skip to content

Commit

Permalink
空白行添加多行花括号自动缩进
Browse files Browse the repository at this point in the history
  • Loading branch information
iwxyi committed Oct 20, 2019
1 parent 8d16028 commit ee5af0b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/key_obrkt.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,17 @@ function provideCompletionItems(document, position, token, context) {
}
// 空白处,单独一个大括号
else if (/^\s*$/.test(left) && /^\]?\s*$/.test(right)) {
// 缩进跟随上面
var prevLine = position.line <= 0 ? ';' : document.lineAt(new vscode.Position(position.line - 1, 0)).text;
var prevIndent = /^(\s*)/.exec(prevLine)[1].length;
var indent = /^(\s*)/.exec(line)[1].length;
if (indent > prevIndent)
vscode.commands.executeCommand('outdent');
else if (indent < prevIndent && indent != 0)
vscode.commands.executeCommand('editor.action.indentLines');
else if (indent < prevIndent && indent == 0)
vscode.commands.executeCommand('editor.action.reindentLines');

vscode.commands.executeCommand('deleteLeft');
vscode.commands.executeCommand('cursorLineEnd');
vscode.commands.executeCommand('editor.action.insertSnippet', { 'snippet': '{\n\t$0\n}' });
Expand Down

0 comments on commit ee5af0b

Please sign in to comment.