Bug 404222 - [typing] Automatic indentation after wrapping a control-structure (if, for) around a block
Summary: [typing] Automatic indentation after wrapping a control-structure (if, for) a...
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.3   Edit
Hardware: All All
: P3 enhancement with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-23 17:56 EDT by gossi CLA
Modified: 2013-03-28 03:30 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description gossi CLA 2013-03-23 17:56:57 EDT
In JavaScript editor, just type the following (it doesnt matter, if this is within a block, like a function, or plain)

Would be cool, to have automatic indentation after manually wrapping code in a control structure (e.g. if-block or any loop), which is a well-known feature from other IDE's. Here is how I imagine this feature:

1. Create some statements
int n = 10;
String foo = "bar";

2. Realize, you need to wrap it with an if-block:
if (canDo == true) {
int n = 10;
String foo = "bar";

3. Mark the end, by adding the closing curly brace: }
if (canDo == true) {
int n = 10;
String foo = "bar";
} // putting this here, should indent the block between the curly braces

Expected result:
if (canDo == true) {
    int n = 10;
    String foo = "bar";
}

Actual result:
if (canDo == true) {
int n = 10;
String foo = "bar";
}


Or make this feature available with a preference setting.
Comment 1 Dani Megert CLA 2013-03-25 05:11:51 EDT
Not exactly what you asked for, but you could enable 'Save Actions' and then have the formatter format all touched lines on save.
Comment 2 gossi CLA 2013-03-27 13:38:22 EDT
Hello Dani,

not exactly what I meant, because this needs me to trigger the formatter. However, it's also not about the formatter, as the formatter takes the whole document into account.

It's more similar to the auto-indentation after writing a method-signature, typing the open curly brace and hit enter. What's happening then is the next line is indented by <one> and the cursor is put there and in the next line, one indentation back is the closing curly brace.

So, what I meant is if you have a chunk of code and you realize you want to wrap it in e.g. an if statement. So you write the if statement where you want to insert it, with the opening curly brace. Then move the cursor down, into the line where you want to place the closing curly brace. Ok, so once you typed it, all the between the opening and closing curly is automatically indented by <one>.

Does this explanation help? Is it clear now?
Comment 3 Dani Megert CLA 2013-03-28 03:30:18 EDT
(In reply to comment #2)
> Hello Dani,
> 
> not exactly what I meant, ...

Right, that's why I said in comment 1: * Not exactly what you asked for *


> Does this explanation help? Is it clear now?

I never mention that it is not clear. That's why the bug got accepted and marked as ASSIGNED ;-).