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

Bug 65949

Summary: [typing] Spaces Only mode: Paste of commented code with wrong indentation
Product: [Eclipse Project] JDT Reporter: MH <mhilpert>
Component: TextAssignee: JDT-Text-Inbox <jdt-text-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: minor    
Priority: P3 CC: a.t.hofkamp, daniel_megert, luis.dediego, markus.kell.r, sbouchet, Tom.Sardella
Version: 2.1.2Keywords: helpwanted
Target Milestone: ---   
Hardware: PC   
OS: Windows 2000   
Whiteboard: stalebug

Description MH CLA 2004-06-07 08:06:57 EDT
I have 2 editors open. Copy one method from one editor to the others creates 
the correct indentaion in the second editor. But when i first comment the 
method, than select and copy it and then paste it in the second editor, the 
pasted code misses 2 spaces between "//" and the code start (for each line).

why i do this? well i often comment methods that i don't need in this class but 
still may handy. when i found the place to copy it to, i just copy&paste the 
comment code and uncomment it in the destination editor. with the wrong paste 
as described above.
Comment 1 Tom Hofmann CLA 2004-07-19 10:59:03 EDT
*** Bug 66180 has been marked as a duplicate of this bug. ***
Comment 2 Tom Hofmann CLA 2004-07-19 10:59:34 EDT
Also see bug 66180 for another detailed case.
Comment 3 MH CLA 2004-07-19 15:47:15 EDT
even with Eclipse 3.0, when i copy a comment (that was indented) and paste this 
in a new line where the cursor is correctly is indented in a method (8 spaces), 
when i press STRG+V (for paste), the resulting comment slashes (//) start at the 
beginning of the line (column 0) and the comment text starts 8 spaces later ...
Comment 4 Iain McGinniss CLA 2004-10-12 06:05:21 EDT
This is a duplicate of bug 65841; could someone mark it as such?
Comment 5 MH CLA 2004-10-12 14:42:07 EDT
This still occurs in 3.0.1
Comment 6 Dani Megert CLA 2004-10-13 03:28:28 EDT
Sure, the bug is till open ==> not fixed.
Comment 7 Dani Megert CLA 2004-10-18 10:51:06 EDT
Re comment 4: it's not quite the same problem: in bug 65841 spaces are added -
we try to treat it as commented code (spaces are added). In this bug the spaces
somehow got lost, the code gets reformatted.
Comment 8 Dani Megert CLA 2006-02-17 03:33:54 EST
M.H. can you confirm that the bug reported in comment 0 and comment 4 differ? Comment 3 is indeed a duplicate of bug 65841.
Comment 9 MH CLA 2006-02-17 06:12:01 EST
I guess it's another bug. Here's how you can reproduced the bug I described in comment #0:

1. In a method (that is indented) insert these 2 lines:

        System.out.println("test");
        System.out.println("test");

2. Comment them (e.g. Source > Toggle comment). Result is correct:

//        System.out.println("test");
//        System.out.println("test");

3. Select those 2 lines (e.g. with mouse), copy (CTRL+C), and insert them 2 lines below, the wrong result is:

//      System.out.println("test");
//      System.out.println("test");

because 2 spaces are suddenly removed after each "//".
Comment 10 Dani Megert CLA 2009-11-06 04:01:50 EST
Works for me using I20091103-0941.
Comment 11 Markus Keller CLA 2009-11-06 08:25:29 EST
To reproduce comment 9 in HEAD, the code formatter's "Tab Policy" must be set to "Spaces only", and "Java > Editor > Typing > When pasting > Adjust indentation" must be turned on.

I think the right fix for this would be to fix the Toggle Comment command: If a line starts with more than two spaces, then don't just prepend "//", but replace the first two spaces by "//".
Comment 12 Albert Hofkamp CLA 2012-09-19 02:52:45 EDT
The proposed solution in comment #11 looks wrong to me, since it means that commented code that did not move has 2 additional spaces indented compared to commented code that was moved.

In my view all commented code should have the same amount of indenting.

Two additional spaces would probably be easiest, as manually prefixing a line with "//" (in column 0) would then also have the same result. However, I can imagine that some people prefer not having additional white space in commented code.
Comment 13 Albert Hofkamp CLA 2012-09-19 02:55:47 EDT
Perhaps when moving/copying a block of commented code, uncomment it, move/copy, and add comments again?
That should give consistent results in every case.
Comment 14 MH CLA 2012-09-20 02:04:33 EDT
Yes, that's the workaround for me. BUt it's a workaround that involves more clicks than necessary. Toggle comments should be very simple: add 2 slashes and remove 2 slashes - each time at the beginning of the lines no matter if the line starts with spaces or not.
Comment 15 Eclipse Genie CLA 2019-11-11 08:30:42 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.