在 PhpStorm 中按下 Enter 按钮后缩进

Indents after pushing Enter button in PhpStorm

我用PhpStorm很久了,以前没遇到过这个问题。问题是,当我键入一些 pare 标签时,例如 <div></div>(从行首开始有缩进)并且光标位于该标签的中间,在我按下 Enter 按钮后,结束标签只是转到行首。

有趣的是,在 .php 文件中一切正常。仅 .html 扩展名存在问题。我只是不知道我该怎么做才能让 IDE 像这样。

我已经检查了 Preferences -> Code style -> HTML. 中的所有调整 一切都与 PHP 中的相同(并且我按下了按钮 "Restore Defaults")。

它是这样工作的(按下 Enter 按钮后):

      <div>

</div>

我希望它是这样的:

     <div>

     </div>

来自你的另一个 post:

I put first some indent to the tag and than push "Enter button". So the first part of the tag stays where it was, but the other goes to the beginning of the line

因此,您手动设置了代码格式,以便缩进不同于执行 代码 > 重新格式化代码 时得到的缩进。 'Smart indent'(在 Enter 上缩进代码 - 设置 | 编辑器 | 常规 | 智能键 Enter section) 不关心你的手动缩进,创建的缩进是基于代码样式设置而不是你手动创建的缩进。您可以将其关闭 - 在这种情况下,下一行将始终缩进到与上一行相同的级别。

如果使用 Code > Reformat Code 重新格式化代码没有帮助,那一定是代码格式化首选项或文件关联的问题...你有没有安装自定义插件? Svelte plugin, for example, registers .html files as Svelte Html Components (https://github.com/dschulten/sveltejs-idea-plugin/issues/2, https://github.com/dschulten/sveltejs-idea-plugin/issues/6),导致类似问题。

另请检查 保留空格 选项是否在 设置中启用 |编辑|代码风格 | HTML |其他 - 当它打开时,现有缩进在重新格式化时不会改变