Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 243533

Summary: [typing] Tab is not indenting line in Java editor
Product: [Eclipse Project] JDT Reporter: Andrew Gvozdev <angvoz.dev>
Component: TextAssignee: Dani Megert <daniel_megert>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert
Version: 3.4   
Target Milestone: 3.5 M2   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
patch
daniel_megert: review-
patch daniel_megert: review-

Description Andrew Gvozdev CLA 2008-08-07 23:23:19 EDT
1. In Window>Preferences>Java>Editor>Typing uncheck "Tab key adjusts the indentation of the current line".
2. Go to the "formatter preference page" (the easiest to follow the link). Create custom style setting "Tab policy" to  "Spaces only"  ("Mixed" also got the problem). Apply the style.
3. Edit Java file. Enabling "Show whitespace characters" to see all spaces/tabs might be beneficial.
Enter the example in the file. Make sure the semicolon at the 3-rd line is at the first position:

void main() {
    for(;;)
;
}

Place the cursor before that single semicolon at the 3-rd line.
4. Press Tab key 3 times. The cursor jumps 8 characters (indenting after "for") the first time and not moving anymore.
The correct behavior would be to advance adding 4 more spaces (equal indentation size) each time - since "Tab key adjusts the indentation of the current line" is unchecked.

See also bug 242707 for identical bug in CDT C++ editor.
Comment 1 Andrew Gvozdev CLA 2008-08-07 23:24:41 EDT
Created attachment 109490 [details]
patch

suggested patch
Comment 2 Andrew Gvozdev CLA 2008-08-07 23:28:30 EDT
Created attachment 109491 [details]
patch

suggested patch
Comment 3 Dani Megert CLA 2008-08-08 05:54:39 EDT
The patches are wrong since they don't check whether the corresponding smart Tab preference is enabled or not.

Fixed in HEAD.
Will be in next M2 build.
Comment 4 Andrew Gvozdev CLA 2008-08-09 12:06:53 EDT
The patch is working fine, thank you Daniel.
Comment 5 Andrew Gvozdev CLA 2008-08-09 13:29:22 EDT
(In reply to comment #4)
> The patch is working fine, thank you Daniel.

I'd like to add something to that. The case stated in the description is working fine. However there is still something wrong. Set preferences as described in the description (also assuming that tab/ident width is 4) and consider following case (spaces are represented by dot "."):

public class Indent {
....void f() {
........;
....}
}

1. Save the file. Editor window tab is not marked with "*".
2. Select and copy to clipboard 5 spaces. Place the cursor just before the semicolon and paste. The spaces are not added. The contents of the editor are not changed, however the editor window tab is marked with "*" indicating that the file changed.
3. Select 2 spaces and copy at the same position. The spaces added.

If you use tab settings, pressing a tab in that position would add indentation. I think that if a user explicitly pastes a sequence of spaces he expects that it would be inserted as well.
Comment 6 Dani Megert CLA 2008-08-11 03:17:14 EDT
Please file a new bug report since pasting and typing are not the same. Also, please check bugzilla first whether there are related bugs for this already.
Comment 7 Andrew Gvozdev CLA 2008-08-12 10:31:39 EDT
New bug 243880 created. Thanks, Daniel.