Reputation: 634
In IntelliJ, when I comment code in Java using the multiline comment, IntelliJ automatically closes the comment at an arbitrary line below the start of the comment. How can I disable this behaviour?
I have unchecked every box in Editor > General > Smart Keys but that didn't stop this behaviour.
I did a search for "comment" in settings and deactivated everything shown, with no luck.
Example: Taking this simple code snippet as an example
public class Foo {
public void doSomething(List<Object> list) {
for(int i=0; i<list.size(); i++) {
Object obj = list.get(i);
System.out.println(obj.getClass());
}
}
}
I add an opening of a multiline comment before the for loop to temporarily replace it with a "for each" style loop. I don't want to delete the original code before I have tested the new loop:
public class Foo {
public void doSomething(List<Object> list) {
/*
for(int i=0; i<list.size(); i++) {
Object obj = list.get(i);
System.out.println(obj.getClass());
}
}
}
I position the cursor at the end of the obj
declaration line and press "Enter" to create a new line for my closing comment. IntelliJ injects a new line with indentation and a second new line with a close multi-comment tag.
public class Foo {
public void doSomething(List<Object> list) {
/*
for(int i=0; i<list.size(); i++) {
Object obj = list.get(i);
*/
System.out.println(obj.getClass());
}
}
}
In this example, the injected close comment is obviously breaking the code. Sometime, that's what I want, but nearly 100% of the time, the close comment injection just breaks everything by, for example, injecting it out of sight. It's then a pain to find out what is broken in the code and why that bit of code had magically appear where it was not wanted.
Expected result: IntelliJ doesn't inject anything unless I purposely ask it to do so (with right-click, choose from the menu or keyboard shortcut).
Actual result: IntelliJ injects */
at an arbitrary line in the code, which generates compilation errors, headaches and hair lost.
Upvotes: 6
Views: 667
Reputation: 2089
It's not possible, there is a related feature request: https://youtrack.jetbrains.com/issue/IDEA-141574
Upvotes: 2