简体   繁体   English

如何在Eclipse的Java Script源代码中设置数组元素的缩进?

[英]How to set indentation of array's elements in Java Script source code in Eclipse?

How can I configure formatting options in Eclipse for Java Script source code so that having this code: 如何在Eclipse for Java Script源代码中配置格式选项,以便具有以下代码:

var o = {
    items: [{
        xtype: 'grid',
        columns: [<cursor here>{header: 'Column One'}],
    }],
};

after pressing Enter I get this Enter我得到这个

var o = {
    items: [{
        xtype: 'grid',
        columns: [
            {header: 'Column One'}],
    }],
};

instead of the default: 而不是默认值:

var o = {
    items: [{
        xtype: 'grid',
        columns: [
                  {header: 'Column One'}],
    }],
};

I'd like to have initializers of array's elements indented with one level of indentation (tab in my case) not aligned with the opening bracket. 我想让数组元素的初始化程序缩进一个级别的缩进(在我的情况下为制表符),而不与左括号对齐。 I can't get the right indentation even manually - given this code 给定此代码,我什至无法手动获得正确的缩进

var o = {
    items: [{
        xtype: 'grid',
        columns: [
{header: 'Column One'}], // cursor at the beginning of this line
    }],
};

after pressing Tab twice I get the same indentation as after pressing Enter above. 两次按Tab ,我得到的缩进与按上面的Enter后相同。
I'm using JavaScript Development Tools ver. 我正在使用JavaScript开发工具版本。 1.3.0.v201103031824 from Eclipse Web Tools Platform. Eclipse Web工具平台上的1.3.0.v201103031824。

Hope this helps albeit a bit late... 希望这会有所帮助,尽管有点晚了...

You can change the Formatter for JavaScript in Eclipse->Preferences 您可以在Eclipse-> Preferences中更改JavaScript的Formatter
Goto JavaScript->Code Style->Formatter 转到JavaScript->代码样式->格式化程序

Edit to create your custom profile and make changes to the following: 编辑以创建您的自定义配置文件,并进行以下更改:
In the Line Wrapping Tab 在“行包装”选项卡中

  • Change Default Indentation for array Initializers to "1" 将数组初始化程序的默认缩进更改为“ 1”
  • Select Expressions->Array Initializers and set the line wrapping policy as desired. 选择“表达式”->“数组初始化器”,然后根据需要设置换行策略。 Wrap all except first seemed OK to me. 包装所有东西,但首先对我来说似乎还可以。
  • Change Indentation policy for the above to "Indent by one" 将以上的缩进策略更改为“一个缩进”
  • Check the Force split box to have the effect always regardless of whether or not a Wrap is required. 选中“ 强制拆分”框以始终具有效果,而不管是否需要包装。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM