格式化时如何停止PhpStorm在XML节点之间插入换行符? [英] How can I stop PhpStorm to insert linebreaks between XML nodes when formatting?

查看:112
本文介绍了格式化时如何停止PhpStorm在XML节点之间插入换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下XML(来自Magento 2):

I have the following XML (from Magento 2):

<item name="address-list" xsi:type="array">
      <item name="component" xsi:type="string">Magento_Checkout/js/view/shipping-address/list</item>
      <item name="displayArea" xsi:type="string">address-list</item>
</item>

使用自动代码格式功能时,我得到以下信息:

When I use the automatic code format function I get the following:

<item name="address-list" xsi:type="array">
        <item name="component"
              xsi:type="string">Magento_Checkout/js/view/shipping-address/list
        </item>
        <item name="displayArea"
              xsi:type="string">address-list
        </item>
</item>

这不再起作用,因为Magento会解释标签之间的空格,例如,组件变为

This is no longer working, because Magento interprets the spaces between the tags, for example, the component becomes

"Magento_Checkout/js/view/shipping-address/list                               "
                                               ^^^^^ Unwanted spaces ^^^^^^^^^

如何使PhpStorm停止插入这些换行符?

How can I make PhpStorm stop to insert those linebreaks?

修改

演示文件:

https://gist.github.com/amenk/c018332373045e3e8b13

格式化之前

格式化后:

设置:

推荐答案

  1. 根据您的描述和屏幕截图:好像是由于右边距而将其包装起来(该值对于您的行而言太低,IDE将这么长的行分成几行).

  1. Based on your description and screenshots: looks like you have it wrapped because of right margin (the value is too low for your lines and IDE splits such long lines into few).

最简单的解决方案是增加右页边距(在当前的IDE版本中,只要可以输入代码样式,就可以按文件类型/语言来执行此操作).在您的情况下,它将位于Settings/Preferences | Editor | Code Style | XML | Other

The easiest solution is to just increase right margin (in current IDE versions it's possible to do this on per file type/language basis, as long it has entry in Code Style). In your case it will be at Settings/Preferences | Editor | Code Style | XML | Other

此外,即使行长于当前右边距,您也可以更改代码样式设置以防止此类换行.为此,请在同一设置页面上查看包裹属性"选项-使用Do not wrap而不是您的Wrap if long.

In addition you may change your code style settings to prevent such wrapping even if line is longer than current right margin. For that look at "Wrap attributes" option at the same settings page -- use Do not wrap instead of yours Wrap if long.

此设置似乎可以在我的设置上正常工作

This setting seem to work fine on my setup:

这篇关于格式化时如何停止PhpStorm在XML节点之间插入换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆