Page 1 of 1

[RESOLVED] "Copy Code" bug

Posted: Mon Dec 14, 2009 3:42 am
by Tom T.
http://forums.informaction.com/viewtopi ... 092#p14092

Bug regarding copying code from within <code> tags.
SeanM wrote:@Giorgio : When I clicked "Select All" on each of the entries, then copied and pasted, each entry was preceded with four (4) spaces (which were subsequently removed). I had not noticed this earlier.
Confirmed, although solved by use of Copy Plain Text, which is my own default for most copying from the Web.

(Note: This add-on is most compatible with Fx 2.x. Extended Copy Menu is better for Fx 3+. Bug and cure confirmed for both browsers with the respective Plain Text copy add-ons.)

Select All > Edit > Copy = [[....addEventListener('DOMContentLoaded',function(){ad_utils.render_ad=function(w)
{w.location=w.location.href.replace(/.*\bTRAILER=([^&]+).*/,'$1')}},true)]]

(I added the double square brackets to make the WYSIWYG content and leading spaces more apparent, and the .... because the forum sw was eliminating all white space beyond a single space.))

Select All > Edit > Copy as Plain Text =
[[addEventListener('DOMContentLoaded',function(){ad_utils.render_ad=function(w)
{w.location=w.location.href.replace(/.*\bTRAILER=([^&]+).*/,'$1')}},true)]]

No leading spaces using either of the Copy as Plain Text methods. Perhaps this should be reported to PHP?

Does anyone here know of a fix that can be implemented locally, or know whether PHPbb Group is aware of this issue?

Re: "Copy Code" bug

Posted: Mon Dec 14, 2009 8:27 pm
by computerfreaker
I'm going to guess this is deliberate...
I'm a member on 2 other phpBB3 forums, and each of them has the same "problem". IIRC, the extra spaces are automatically clipped on post submission... if my recollection is correct, that would make this a deliberate feature, probably to keep users from getting the code tag mixed up with the actual code. ;)

Re: "Copy Code" bug

Posted: Tue Dec 15, 2009 12:22 am
by Tom T.
computerfreaker wrote:I'm going to guess this is deliberate...
I'm a member on 2 other phpBB3 forums, and each of them has the same "problem". IIRC, the extra spaces are automatically clipped on post submission... if my recollection is correct, that would make this a deliberate feature, probably to keep users from getting the code tag mixed up with the actual code. ;)
I'm not following you. The extra spaces were in fact left in when the code was posted, although in some invisible form. But see above: I successfully reproduced the extra-space issue by copying the code with "Select All" > Edit > Copy, then paste into Wordpad. The fact that "Copy as Plain Text" solved the issue indicates that there's some formatting that's putting in the extra spaces.

I'm not understanding how there's any danger of getting the "code" tag, since "Select All" highlights only the code itself.

Re: "Copy Code" bug

Posted: Tue Dec 15, 2009 1:27 am
by computerfreaker
What I'm saying is like this...

* User hits, say, the "Quote" button
* Quoted post, including code tags, comes up
* If there's no extra spaces, a non-phpBB-savvy user could possibly get the code tag mixed up with the actual code; however, because of the extra spaces, that would be hard to do
* The extra spaces appear to be automatically trimmed out of the code tag upon submission, so IMHO it isn't that big a deal...

Re: "Copy Code" bug

Posted: Tue Dec 15, 2009 2:01 am
by Tom T.
computerfreaker wrote:What I'm saying is like this...

* User hits, say, the "Quote" button
* Quoted post, including code tags, comes up
But you wouldn't (or shouldn't) copy code from a quote of a post. You should copy it from the actual post in which it was placed -- which was the situation here.
computerfreaker wrote: * The extra spaces appear to be automatically trimmed out of the code tag upon submission, so IMHO it isn't that big a deal...
But they aren't. You don't see them in the slider bar window, true. They're invisible, caused by some sort of formatting which is reproducibly removed by any Plain Text copy add-on. Do what I did and reproduce the issue yourself. And OP SeanM reported this -- in fact, his report was the impetus for this thread.

Try it. Select All > Edit > Copy > paste into, say, Wordpad, and see if it isn't indented four spaces.

Re: "Copy Code" bug

Posted: Tue Dec 15, 2009 6:05 am
by computerfreaker
computerfreaker wrote:What I'm saying is like this...

* User hits, say, the "Quote" button
* Quoted post, including code tags, comes up
Tom T. wrote:But you wouldn't (or shouldn't) copy code from a quote of a post. You should copy it from the actual post in which it was placed -- which was the situation here.
I finally see what you're getting at. I was thinking of quoting someone else's code, say, to critique it. :oops:
computerfreaker wrote: * The extra spaces appear to be automatically trimmed out of the code tag upon submission, so IMHO it isn't that big a deal...
Tom T. wrote:But they aren't. You don't see them in the slider bar window, true. They're invisible, caused by some sort of formatting which is reproducibly removed by any Plain Text copy add-on. Do what I did and reproduce the issue yourself. And OP SeanM reported this -- in fact, his report was the impetus for this thread.

Try it. Select All > Edit > Copy > paste into, say, Wordpad, and see if it isn't indented four spaces.
I've known about the four-spaces thing for some time (since I joined another phpBB forum almost a year ago), but hadn't thought of it as an issue... however, now that I've properly adjusted my frame of reference to match yours, I see what you're saying. You're right, that's a big inconvenience to anyone trying to move code from a post to an IDE...

Re: "Copy Code" bug

Posted: Tue Dec 15, 2009 6:30 am
by Tom T.
computerfreaker wrote: I see what you're saying. You're right, that's a big inconvenience to anyone trying to move code from a post to an IDE...
Or in this case, to make a new entry in about:config. Pasting in the string value with the four spaces would invalidate the code. I just tried this with a fake value -- the string value does indeed keep the four blank spaces, surely a deal-killer.

Perhaps first going back to the original thread where this came up, and following the discussion and actions of Giorgio providing code for us to copy and paste into a new about-config value, would have made this more clear, but I'm glad we got it straightened out.

IMHO, the bug report still stands. Cheers. :D

Re: "Copy Code" bug

Posted: Tue Dec 15, 2009 11:17 am
by Giorgio Maone
Fixed, thanks.

Re: [RESOLVED] "Copy Code" bug

Posted: Thu Feb 11, 2016 10:19 pm
by barbaz
This is resolved only for non-syntax-highlighted code

These two code snippets should be identical and thus copy identical.

Working:

Code: Select all

for (var a of window.localStorage.get('dummy')) {
  // do something
}
Not work - not only in the way the OP describes but also added (in my post) a space at the end of the code:

Code: Select all

for (var a of window.localStorage.get('dummy')) {
  // do something
}