New method completion should add newline after closing brace
已回答
This is related to https://intellij-support.jetbrains.com/hc/en-us/community/posts/360010011640-Indent-line-comments-add-line-space-after-starting-new-method.
Even if I set min blank lines around method to 1, if I'm between two methods:
public void m1() {}
<-- cursor at beginning of this blank line
public void m2() {}
I hit Enter and type "public void x() {" and hit Enter again, I'm now here:
public void m1() {}
public void x() {
<-- cursor here, but no blank line after closing brace
}
public void m2() {}
There's no blank line after x(), so I have to manually insert it.
How can I get IntelliJ to automatically add that newline so it looks like this:
public void m1() {}
public void x() {
<-- cursor here, ready to implement
}
public void m2() {}
请先登录再写评论。
Is the blank line inserted when you invoke "Reformat file" action?
Yes but I don't want to reformat the whole file, that introduces unnecessary diffs that make code reviews more confusing, and eliminates the occasionally necessary hand-crafted formatting for unique cases.
I just looked at the keymap, I guess I can do Option-Cmd-Return to add a new line below current before I start typing the new method, but it'd be nice if IntelliJ could just handle this. Is there a "new method" template I can modify to add a newline at the end?
You can use "Only changes uncommited to VCS" option for reformating: https://i.imgur.com/WvWMXnW.png
I could, but why should I go through all that extra work of more key presses and a dialog? Can't IntelliJ just follow my "blank lines around method" automatically when it completes the method stub for me?
Here is the usability problem in IntelliJ IDEA bug tracker: https://youtrack.jetbrains.com/issue/IDEA-286306
Feel free to follow.
For the time being, the only option is to reformat manually.