Java在IntelliJ中换行不正常

huangapple go评论62阅读模式
英文:

Java caret not going to the next line correctly in IntelliJ

问题

在Java中编写Switch语句时(我使用IntelliJ IDEA),闪烁的光标,或者叫插入符,不能正确地移到下一行。这并不是一个很大的问题,只是一个让我不太确定如何修复的烦恼。

当我为switch代码块编写一个case:

switch(switchValue){
    case 1:
        System.out.println("值为1");
        break;
}

在"break;"之后,当我输入时,光标停留在case 1代码块内:

switch(switchValue){
    case 1:
        System.out.println("值为1");
        break;
        <-- 光标在这里
}

当我按退格键将光标移回,以便创建一个新的case时,该行会回到"break;"的末尾;

switch(switchValue){
    case 1:
        System.out.println("值为1");
        break;<-- 光标在这里
}

我唯一能够移动光标以创建新的case 2的方法是,在按下回车后手动使用方向键向后移动4个空格。是否有快捷键可以在不需要额外步骤的情况下创建新的case?

switch(switchValue){
    case 1:
        System.out.println("值为1");
        break;
    <-- 光标在这里然后我使用方向键    
    case 2:
        System.out.println("值为2");
        break;
}

这是一个相当晦涩的小问题,我似乎找不到答案。

英文:

When I write a Switch statement in Java (I use IntelliJ IDEA), the blinking cursor, or caret, doesn't go to the next line correctly. It's not really a huge problem, but just an annoyance I'm not sure how to fix.

When I write a case for a switch code block:

switch(switchValue){
    case 1:
        System.out.println(&quot;Value was 1&quot;);
        break;
}

After the 'break;', when I enter the cursor stays inside the case 1 code block

switch(switchValue){
    case 1:
        System.out.println(&quot;Value was 1&quot;);
        break;
        &lt;-- The cursor goes here
}

And when I backspace to move it back so I can make a new case, the line just goes back to the end of the break;

switch(switchValue){
    case 1:
        System.out.println(&quot;Value was 1&quot;);
        break;&lt;-- cursor goes here
}

The only way I can move it to create a new case 2 is to manually use my directional keys 4 spaces after I press enter. Is there a keyboard shortcut where I can create a new case without the extra steps?

switch(switchValue){
    case 1:
        System.out.println(&quot;Value was 1&quot;);
        break;
    &lt;-- cursor goes here and after I use the directional keys    
    case 2:
        System.out.println(&quot;Value was 2&quot;);
        break;
}

This was a really obscure minor issue I can't seem to find the answer for.

答案1

得分: 1

我认为在发布问题后解决了自己的问题。

如果在“break;”后的下一行输入“case 2:”,IntelliJ IDEA会自动格式化该案例并将其移动到正确的位置,无需任何麻烦。

switch(switchValue){
    case 1:
        System.out.println("值为1");
        break;
    case 2:
}

一旦您完成了带有冒号的case语句,编辑器将自动格式化该行并将语句移动到正确的位置。

switch(switchValue){
    case 1:
        System.out.println("值为1");
        break;
    case 2:
}
英文:

I think I fixed my own issue after posting the question.

If I just type "case 2:" after going to the next line after the "break;", IntelliJ IDEA will automatically format the case and move it to the correct position without any hassle.

switch(switchValue){
    case 1:
        System.out.println(&quot;Value was 1&quot;);
        break;
        case 2:
}

The moment you finish the case statement with the colon, the editor will automatically format the line and move the statement to the correct position.

switch(switchValue){
    case 1:
        System.out.println(&quot;Value was 1&quot;);
        break;
        case 2:
}

huangapple
  • 本文由 发表于 2020年7月26日 00:00:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/63090464.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定