Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 351771 - Pasting changes the indent of the pasted code.
Summary: Pasting changes the indent of the pasted code.
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: PDT (show other bugs)
Version: unspecified   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 normal with 7 votes (vote)
Target Milestone: ---   Edit
Assignee: PHP UI CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-11 19:23 EDT by Andrew Eddie CLA
Modified: 2020-05-14 11:44 EDT (History)
19 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Eddie CLA 2011-07-11 19:23:37 EDT
PHP Development Tools (PDT) SDK Feature	3.0.0.v20110516-1100-77--84_23JBVgSVXO7XGJz0VLa9O	org.eclipse.php.sdk.feature.group	Eclipse.org

Cut and paste is yielding unusual results, namely, the paste operation seems to be running some sort of formatting over the pasted text to adjust the indenting.

As simple example is to copy-paste a standard Docblock, eg:

	/**
	 * Method to translate a text string with inputs to the output buffer.
	 *
	 * @param	string		The language string to translate.
	 * @return	integer		The length of the translated string.
	 * @since	1.0
	 */

The result is:

	/**
	* Method to translate a text string with inputs to the output buffer.
	*
	* @param	string		The language string to translate.
	* @return	integer		The length of the translated string.
	* @since	1.0
	*/

Note, the stars are aligned with the slash on the first line, not the first star on the first line.  That's a simple example, it gets even worse with PHP code.
Comment 1 Zhongwei Zhao CLA 2011-07-11 23:47:58 EDT
hi,

we auto format the php code/comment when user paste it,and we have fixed the above issue in the latest code(head).

Hope you try our nightly build to see if it is ok for you!
Comment 2 Jacob Weber CLA 2011-07-15 14:12:50 EDT
Another example:

	function x() {
		if ($x == 1) {
			$x = 1;
		}
	}

becomes:

	function x() {
	if ($x == 1) {
	$x = 1;
	}
	}

Do you think this will be fixed in an official release any time soon? I'm hesitant to start working off the nightly builds.
Comment 3 Zhongwei Zhao CLA 2011-07-16 23:45:59 EDT
(In reply to comment #2)
> Another example:
> 
>     function x() {
>         if ($x == 1) {
>             $x = 1;
>         }
>     }
> 
> becomes:
> 
>     function x() {
>     if ($x == 1) {
>     $x = 1;
>     }
>     }
> 
> Do you think this will be fixed in an official release any time soon? I'm
> hesitant to start working off the nightly builds.

hi,

When I paste:
    function x() {
        if ($x == 1) {
            $x = 1;
        }
    }

I get(I set "Tab policy" to "tab" ):
	function x() {
		if ($x == 1) {
			$x = 1;
		}
	}
if I set  "Tab policy" to "spaces" and "Indentation size" to "3",I get:
    function x() {
        if ($x == 1) {
            $x = 1;
        }
    }
Comment 4 Jacob Weber CLA 2011-07-16 23:48:06 EDT
In the Indigo release version or the nightly build? I'm using the release.
Comment 5 Zhongwei Zhao CLA 2011-07-16 23:59:14 EDT
so I think you use an old version of pdt,you can try pdt's newest nightly build:https://hudson.eclipse.org/hudson/job/cbi-pdt-3.0-indigo/166/artifact/build/N201107150957/pdt-Update-N201107150957.zip
Comment 6 jucianoaraujo CLA 2011-07-20 16:28:58 EDT
Is there any way to disable this paste formatting feature? This really sucks... i've installed the nightly build but it still is formatting wrongly
Comment 7 Zhongwei Zhao CLA 2011-07-22 04:22:06 EDT
(In reply to comment #6)
> Is there any way to disable this paste formatting feature? This really sucks...
> i've installed the nightly build but it still is formatting wrongly

hi,

This is called smart paste,but I could not find where to disable it in UI:(

I will try to add it later
Comment 8 Nicolas Ternisien CLA 2011-08-05 04:18:14 EDT
I confirm the bug... Is it something easy to fix, because it also totally breaks content of multiline string for example, adding/removing (as it wishes) tabs on each line.
Comment 9 UncleRus CLA 2011-10-27 11:41:45 EDT
Please fix it!
Or just allow us switch this "smart" paste off!
Comment 10 Glen A. CLA 2011-11-11 07:17:26 EST
Zhao,

This has a big impact on efficiency, please fix these issues and provide a stable release as soon as possible.

Here is another simple example:

$x = array(
    'one' => array(
        1 => 2
    ),
    'more' => 'here'
);

Results in:

$x = array(
    'one' => array(
1 => 2
),
    'more' => 'here'
);

*Also*, if you do something like this:

$x = $y->z(
'abc'
);

Put your cursor in front of the 'abc' and hit tab, and it'll insert a tab instead of 4 spaces (as configured).

I have the following preferences:

/instance/org.eclipse.ui.editors/spacesForTabs=true
/instance/org.eclipse.php.core/org.eclipse.php.core.phpForamtterUseTabs=false
/instance/org.eclipse.php.core/org.eclipse.php.core.phpForamtterIndentationSize=4

This is Eclipse Version: 3.7.1 and PDT 3.0.0.v20110516.
Comment 11 Kristian Wiborg CLA 2011-11-13 15:22:58 EST
Please create a fix for this issue. I have always had problems with the way Eclipse does indentation when pasting code. My usual problem is the one mentioned here (I think): https://bugs.eclipse.org/bugs/show_bug.cgi?id=279358 - This is easy and quick to fix (but still a bit annoying). 

But this new problem is seriously annoying and takes long time to fix (e.g. if you paste a function with 100 lines of code or more).
Comment 12 Kristian Wiborg CLA 2011-11-13 15:25:58 EST
(In reply to comment #11)
> Please create a fix for this issue. I have always had problems with the way
> Eclipse does indentation when pasting code. My usual problem is the one
> mentioned here (I think): https://bugs.eclipse.org/bugs/show_bug.cgi?id=279358
> - This is easy and quick to fix (but still a bit annoying). 
> 
> But this new problem is seriously annoying and takes long time to fix (e.g. if
> you paste a function with 100 lines of code or more).

BTW I'm using Version: 3.7.1 Build id: M20110909-1335.   PHP Development Tools (PDT) All-In-One SDK 3.0.0.v20110516-1100-77--7C91A5Ad77OH_pV_hSBYHKz0
Comment 13 pphilipp CLA 2012-01-27 04:29:02 EST
A similar issue seems to be that if I copy paste multiple lines the line ending is modified. 
In my case a carriage return (\r) is added to the line end, even if the configuration says use only new line (\n).
The strange thing is, that if I replace existing code - this means any visible char, the indent and the line ending are properly maintained.
But if I simply paste onto a new line everything is messed up.
Thus I ended up to write always a dot, and replace it on paste...
Tested with the latest indigo nightly (build #300).
Comment 14 pphilipp CLA 2012-02-21 05:05:44 EST
The latest nightly build (https://hudson.eclipse.org/hudson/job/cbi-pdt-3.0-indigo/327) seems to fix some of the copy / paste issues.
Many thanks @zzhongwei!!
Comment 15 Sean Robertson CLA 2012-07-26 13:39:46 EDT
This is still happening in Juno (4.2.0).  Very annoying.
Comment 16 barduck CLA 2012-08-05 09:18:03 EDT
I am yet to see a feature in any software project that has the word "smart" in it and doesn't annoy some of its users, "smart paste" is no exception.

Please fix this or/and allow us to disable this so called "smart paste".

thanks.
Comment 17 Tony Vermeiren CLA 2012-10-05 07:18:31 EDT
Try this, it worked for me.

open workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.php.ui.prefs

add "smartPaste=false" at the end

save & restart eclipse
Comment 18 Ben Johnson CLA 2012-10-29 10:41:24 EDT
Agreed; this behavior is annoying and slows me down more than any other UI bug I've experienced.

Tony Vermeiren, taking that measure does not change the behavior in my case.

Reproducing this bug is as simple as copy/pasting any array. For example:

Copying this code

return array(
	'success' => TRUE,
	'data' => $r,
);

and pasting it yields

return array(
		'success' => TRUE,
		'data' => $r,
);

Version: Juno Service Release 1
Build id: 20121004-1855
Comment 19 Jacek Pospychala CLA 2012-11-05 04:52:45 EST
I just tried all code samples in this bug and see that they're formatted properly when pasted to PHP editor.

I tried with nightly build from http://download.eclipse.org/tools/pdt/updates/nightly

(In reply to comment #18)
> Copying this code
> 
> return array(
> 	'success' => TRUE,
> 	'data' => $r,
> );
> 
> and pasting it yields
> 
> return array(
> 		'success' => TRUE,
> 		'data' => $r,
> );

this is correct default behavior of PHP formatter. Default setting is indent with tabs using size 2 (=insert 2 tabs). Please adjust it to what is your preference.

I'm marking it as FIXED. Please comment if you disagree.
Thanks!
Comment 20 Ben Johnson CLA 2012-11-05 10:55:59 EST
Jacek, thank you!

You are absolutely right; changing the "Default indentation for array initializers" from 2 to 1 caused Eclipse to behave "as expected".

I wonder why the default is 2; maybe this value is aimed more at users who prefer spaces over tabs.

In any event, thank you for setting the record straight!
Comment 21 b d CLA 2012-11-30 13:19:43 EST
For those that have trouble finding the preferences, in PDT see:

PHP > Code Style > Formatter > Default indentation for array initializers
Comment 22 Ben Johnson CLA 2012-12-23 23:42:09 EST
I find myself returning to this report some months later; I was trying to remember how to disable this most annoying "feature" in a new Eclipse installation.

It took me a while to fully realize that there are two separate behaviors here that contribute to my frustration around default PHP code formatting in Eclipse: Smart Paste and Default indentation for array initializers being set to 2 (instead of 1).

The comment from Tony Vermeiren 2012-10-05 07:18:31 EDT does indeed work for disabling Smart Paste; thank you, Tony.

And "b d", thanks for pointing-out the array initializers setting within the GUI; that was most helpful.
Comment 23 Jacob Weber CLA 2014-12-18 13:58:38 EST
OK, I'm glad this smartPaste thing can be turned off, but can this really be considered "fixed" if there's no GUI for it? You can't expect users to go digging into bug reports for such a basic problem. This is still happening in Eclipse 4.4.1 with PDT 3.3.1.
Comment 24 Dawid Pakula CLA 2014-12-18 14:43:22 EST
(In reply to Jacob Weber from comment #23)
> OK, I'm glad this smartPaste thing can be turned off, but can this really be
> considered "fixed" if there's no GUI for it? You can't expect users to go
> digging into bug reports for such a basic problem. This is still happening
> in Eclipse 4.4.1 with PDT 3.3.1.

What you mean by "no GUI for it" ?

GUI to disable/enable:
Preferences -> PHP -> Editor -> Typing -> Adjust indentation

GUI to define indentation:
Preferences -> PHP -> Code Style -> Formatter -> Edit -> Indentation

If indentation is invalid, should be reported as new bug.
Comment 25 Jacob Weber CLA 2014-12-18 14:52:23 EST
Sorry, didn't realize that "Adjust indentation" was the same thing as smartPaste.
Comment 26 Sylvia Tancheva CLA 2015-01-15 08:03:17 EST
Yes - "Adjust Indentation' is in the section titled 'When pasting'.

I'm closing this bug as it's been set as Fixed for more than 2 years and I could not reproduce any of the above given examples.

If someone disagree or have issues please reopen with a concrete description or open a new bug.