Browsers' misbehavior of COPY from println's console

65 views
Skip to first unread message

Bob Lyon

unread,
Aug 14, 2013, 3:39:53 PM8/14/13
to khan-academy-javas...@googlegroups.com
This is more of a complaint phrased as a question...

I have a program, xx that writes Javascript code to the text area of the Processing environment's console via println().  The intent is for the user to COPY and PASTE that code into a new program.

If I use Chrome, it leaves the copy with same indentation that it was written with.  If I use Firefox, all blank lines and leading white space is eliminated.  Have no access to Safari or IE, so I don't know those behaviors (though I've seen lots of programs with lots of blanks lines which I assume were copy & pasted by IE users).

Is there some way to tell the browsers that "copy" mean "copy" and not "edit"?

Thanks.
/Bob

Bob Lyon

unread,
Aug 14, 2013, 3:43:03 PM8/14/13
to khan-academy-javas...@googlegroups.com

Larry Serflaten

unread,
Aug 14, 2013, 6:38:38 PM8/14/13
to khan-academy-javas...@googlegroups.com

 Bob Lyon wrote:

Is there some way to tell the browsers that "copy" mean "copy" and not "edit"?
 
FWIW:  I've used both IE9 and IE10 at Khan Academy and have not found a way to copy either the code window text or the text in the canvas console.  With IE10 I find even webpages who explicitly use client side code (javascript) to access the clipboard are also not allowed to add anything to the clipboard. (I get a dialog that asks if I want to allow access, and even after saying Yes, there is nothing added to the clipboard that can be pasted...)
 
Paste operations work OK (when there is something already on the clipboard) , but Copy has been disabled by default (I don't know if there is a setting somewhere to change the default).
 
When I want to copy stuff from KA, I have to fire up Chrome.
 
I don't have Firefox, but here is something that may have bearing on your problem.  If (while using Firefox) you copy some text from KA and paste it into Notepad, is the formatting lost there as well?  If Notepad shows the correct formatting (which I have seen happen on other websites) then its not a Copy problem but more of a Paste problem, in that the receiving application tries to deal with the content that is being pasted.  When you then Copy the text from Notepad, and paste that into the code area, is the format retained?  (That was the solution to the 'other website's copy and paste problem - use Notepad as an intermediary step)
 
Good luck!
LFS
 
 

Bob Lyon

unread,
Aug 14, 2013, 7:09:17 PM8/14/13
to khan-academy-javas...@googlegroups.com
I don't have Notepad, but my experiment  is similar.  Copying from Chrome to Firefox preserves formatting.  Copying from Firefox to Chrome does not.  Similarly, copying from Chrome to vi in a "terminal window" on Linux preserves formatting while copying from Firefox does not.

I am shocked and amazed re. IE.

Thanks.
/Bob

primenum...@gmail.com

unread,
Oct 11, 2015, 11:06:18 AM10/11/15
to Khan Academy Javascript Technical Q&A
You could try having each line be a println() and then using No-Break Spaces (\u00a0). T#1B12P demonstrated this once.

Bob Lyon

unread,
Oct 12, 2015, 7:05:23 PM10/12/15
to Khan Academy Javascript Technical Q&A, primenum...@gmail.com
> You could try having each line be a println() and then using No-Break Spaces (\u00a0). T#1B12P demonstrated this once.

BINGO!  This worked as advertised with my Firefox browser on Linux.

I'd would be interested in folks confirming the desired behavior on Windows and Macs.  Same test program - https://www.khanacademy.org/computer-programming/button-generator/1847123742  

Thank you.

Larry Serflaten

unread,
Oct 13, 2015, 1:32:21 AM10/13/15
to Khan Academy Javascript Technical Q&A, primenum...@gmail.com


 Bob Lyon wrote:

I'd would be interested in folks confirming the desired behavior on Windows and Macs.  Same test program - https://www.khanacademy.org/computer-programming/button-generator/1847123742  


Using IE the code looks OK in the console but when copied and pasted into the code editor I get double spacing.

See if this does any better for you:

var bk = String.fromCharCode(10);
var msg = "// These comments should be properly" + bk;
msg += "// spaced in the console pane, as well as" + bk;
msg += "// when they are copy/pasted into the code pane.";

println(msg);

I know it works OK for IE....

LFS
 

Bob Lyon

unread,
Oct 13, 2015, 10:30:12 PM10/13/15
to Khan Academy Javascript Technical Q&A, primenum...@gmail.com


On Monday, October 12, 2015 at 10:32:21 PM UTC-7, Larry Serflaten wrote:


Using IE the code looks OK in the console but when copied and pasted into the code editor I get double spacing.

See if this does any better for you:

var bk = String.fromCharCode(10);
var msg = "// These comments should be properly" + bk;
msg += "// spaced in the console pane, as well as" + bk;
msg += "// when they are copy/pasted into the code pane.";

println(msg);

I know it works OK for IE....

LFS
 

My program now appends a  String.fromCharCode(10) character to the end of every line that is emitted via println.  My browsers do not mind at all.  Let me know if that works for you. 

Thanks.

/Bob
Reply all
Reply to author
Forward
0 new messages