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

Bug 350057

Summary: Pasting from clipboard sometimes messing up indentation
Product: [Tools] CDT Reporter: Jonathan Watt <jwatt>
Component: cdt-editorAssignee: Project Inbox <cdt-editor-inbox>
Status: CLOSED DUPLICATE QA Contact: Anton Leherbauer <aleherb+eclipse>
Severity: normal    
Priority: P3 CC: cdtdoug, yevshif
Version: 8.0   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Jonathan Watt CLA 2011-06-22 10:10:45 EDT
I have my C++ code style set to insert two spaces for all types of indentation, never tabs.

Say I have a .cpp file containing:

-----------
int
foo() {
  if (true) {
    void(0);
  }
}

int
bar() {
  
}
----------

Note that there's two spaces on the blank line in 'bar'. Now say I select and copy from 'foo', where the selection starts with the "i" of the "if" and ends with the ";" after the void(0). If I now put the cursor at the end of the two spaces on the empty line in 'bar' and paste, the "void(0);" line that is pasted is indented by six spaces instead of 4.
Comment 1 Jonathan Watt CLA 2011-06-22 10:13:24 EDT
In fact I can end the selection with the closing "}" of the 'if' to paste the entire block, and then the pasted closing "}" also gets incorrectly indented by four spaces instead of two.
Comment 2 Jonathan Watt CLA 2011-06-22 10:21:08 EDT
The problem seems to happen only if I select from the "i" of the "if" without selecting the whitespace that proceeds it. I guess the issue is that the "if" line in the clipboard then has less indentation than its body, and Eclipse fails to correct this to the code style in use when pasting.

For what it's worth, I encountered this while selecting an 'if' clause out of an 'else-if' block, so there was no leading whitespace to select given that the 'if' was proceeded on the line by the 'else'.
Comment 3 Anton Leherbauer CLA 2011-07-21 07:53:24 EDT
There's a bug for that.

*** This bug has been marked as a duplicate of bug 279358 ***