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 e5fde73 commit 8d16028
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/bind_enter.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ function toIndent(editor, document, position)
// 上一行是分支,必须缩进
if (/^\s*(if|for|while|foreach|switch)\s*\(.*\)[^;]*$/.test(prevLine)) {

}
// 左括号,也需要缩进
else if (/^\s*{\s*$/.test(line)) {

}
// 如果是右花括号,不缩进
else if (line.indexOf('}') > -1) {
return true;
}
// 判断上一行是不是同样没有分号
else if (!/^\s*$/.test(prevLine) && /^[^;]+$/.test(prevLine))
Expand Down Expand Up @@ -147,7 +155,10 @@ function toIndent(editor, document, position)

// 单个 if 后面的句子,是否需要 outindent
var outdent = false;
if (line.indexOf(';') > -1
if (prevLine.indexOf('{') == -1) {
outdent = false;
}
else if (line.indexOf(';') > -1
&& ((/^[^;]+$/.test(prevLine) || /^[^;]+(\(.+\))?[^;]*$/.test(prevLine))
&& /^(\s*)/.exec(line)[1].length > /^(\s*)/.exec(prevLine)[1].length)
) {
Expand Down

0 comments on commit 8d16028

Please sign in to comment.