Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Eclipse indent new line with 1 tab after JavaScript array initializer?

I'm using Eclipse to edit JavaScript files and I guess I'm "doing it wrong". Given the following code, where
» represents a tab,
· represents a space, and
| represents the cursor:

function·foo()·{
»   var·baz·=·[|
}

If I hit enter at this point, I get

function·foo()·{
»   var·baz·=·[
»   ···········|
}

Yuck. I would much rather get

function·foo()·{
»   var·baz·=·[
»   »   |
}

I've dug through the various "Typing" and "Formatter" preferences to no success. Did I overlook something? Or is there a particular incantation that I must chant or spell I can cast on Eclipse, to make it behave this way? Thanks.

like image 350
G-Wiz Avatar asked Jul 23 '10 15:07

G-Wiz


1 Answers

Indeed a (bug|weird feature|annoyance) of the Eclipse Javascript editor.

The quickest hack way I found to overcome this is to quickly insert an empty js object and hit the Format shortcut and let the Eclipse javascript editor to sort out the tabs:

function·foo()·{var·baz·=·[{}]}

hit format:

function·foo()·{
»   var·baz·=·[
»   »   {}
»   ]
}

This also works for an empty string with double / single quotes instead of an empty object.

Note: The Aptana v2 js editor works fine.

like image 156
Angelos Avatar answered Oct 27 '22 11:10

Angelos