Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 331501 - [formatting] Wrong indentation if new line is inserted before opening a curly bracket
Summary: [formatting] Wrong indentation if new line is inserted before opening a curly...
Status: NEW
Alias: None
Product: JSDT
Classification: WebTools
Component: General (show other bugs)
Version: 3.2.2   Edit
Hardware: PC Windows Vista
: P3 normal with 2 votes (vote)
Target Milestone: Future   Edit
Assignee: Project Inbox CLA
QA Contact: Chris Jaun CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-01 01:38 EST by Mauro Molinari CLA
Modified: 2013-07-18 14:07 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mauro Molinari CLA 2010-12-01 01:38:01 EST
STEPS TO REPRO
1. create a js file
2. type:

function test()

3. go to next line and add a "{"
4. go to next line

EXPECTED BEHAVIOUR
The JavaScript editor adds the closing bracket for me, putting it indented like the opening one:

function test()
{
  |
}

The Java Editor behaves in this way.

OBSERVED BEHAVIOUR
The JavaScript editor adds the closing bracket for me, but it's indented the wrong way:

function test()
{
  |}
Comment 1 Wade Tracy CLA 2010-12-08 12:53:22 EST
This also occurs when entering a new line after for, if, else, do, etc. except that in those cases, both of the braces are indented:

STEPS TO REPRO
1. create a js file
2. type:

if(expression)

3. go to next line and add a "{"
4. go to next line

EXPECTED BEHAVIOUR
The JavaScript editor removes the indentation and adds the closing bracket for me, putting it indented like the opening one:

if(expression)
{
  |
}

The Java Editor behaves in this way.

OBSERVED BEHAVIOUR
The JavaScript editor keeps the indent and adds the closing bracket for me, but it's indented the wrong way:

if(expression)
   {
   |
   }
Comment 2 Robert Schultz CLA 2011-01-20 22:22:49 EST
So this is the most annoying bug in the entire universe, so I've spent the past several hours trying to fix it.

I've narrowed down the problem code.

Class: org.eclipse.wst.jsdt.internal.ui.text.java.JavaAutoIndentStrategy
Method: public void customizeDocumentCommand(IDocument d, DocumentCommand c)

This method is called whenever you type characters. It then formats the document correctly.

In JDT for example, when you type the '{' character, this method is called and then the { is de-indented correctly.

In JSDT however, this method is never called when you type the '{' character.

I've spent a while trying to figure out WHY this method isn't getting called, and have not yet come up with a reason.