14

IntelliJ does some odd formatting with Javascript code and I am trying to figure out how to get it to stop formatting this way. Whenever I chain jQuery functions together, it over indents the auto created code such as this:

$('#something').focus(function() {
    /* Do some stuff */
}).blur(function() {
        /* this is where the cursor and closing braces end up */
        })

I want it to look like this:

$('#something').focus(function() {
    /* Do some stuff */
}).blur(function() {
    /* cursor and closing braces indented normally */
});

How do I change this?

intargc
  • 249

2 Answers2

11

As @intarg mentions, in the comments. You can change File|Settings|Code Style|General and on the Javascript tab set Continuation Indent to 0 for Javascript.

That will get you most of what you want. the problem is that your code is actually all 1 long statement.

$('#something').focus(
function() {
    /* Do some stuff */
}).blur(function() {
    /* this is where the cursor and closing braces end up */
})

Not sure that there is a relevant option to prevent a line break after focus(

Oh, and be sure that you have the Javascript code sample tab active when you are changing options - otherwise you will not change them for Javascript.

EDIT: Now that I have looked further. The Javascript formatter is coded to add a linebreak in that specific case, there isn't an option for it.

sylvanaar
  • 2,305
0

All the settings you need to control code formatting in intellij are in File>Other Settings>Template Settings.

If Javascript is not listed (i.e you've not installed a Javascript plugin), you can define the code formatting under the General tab and then the Other tab. There will be options for controlling indentation and spacing.