1094: Copy/paste source code

jeff****@gmai***** (Google Code) (Is this you? Claim this profile.)
chipx86
chipx86
Oct. 14, 2014
3662
The diff view should allow for proper copy and pasting from a browser.

A standard copy/paste of the following source code (new added function, no
existing code on the left):

    char_t *p_pos = strchr(p_str, old);
    if (new == old) {
        return;
    }
    while (p_pos != NULL) {
        *p_pos = new;
        p_pos  = strchr(p_pos + 1, old);
    }

shows up pasted as this:

 562  	

    char_t *p_pos = strchr(p_str, old);

	

	563 	

	

	564 	

    if (new == old) {

	

	565 	

        return;

	

	566 	

    }

	

	567 	

	

	568 	

    while (p_pos != NULL) {

	

	569 	

        *p_pos = new;

	

	570 	

        p_pos  = strchr(p_pos + 1, old);

	

	571 	

    }

You can imagine how confusing it looks when there's a diff on the left to
copy from.

If you control and click/drag (firefox), then copy/paste, it shows up as
this (just extra newlines):

    char_t *p_pos = strchr(p_str, old);

    if (new == old) {

        return;

    }

    while (p_pos != NULL) {

        *p_pos = new;

        p_pos  = strchr(p_pos + 1, old);

    }

It'd be nice to be able to more easily copy/paste from the diff view in all
browsers.
chipx86
#1 chipx86
I don't know that we can control any of this. Pretty sure this is up to the browser.
  • +Confirmed
  • -Priority-Medium
    +Priority-Low
    +Browser
    +Component-DiffViewer
chipx86
#2 chipx86
Yeah, we won't be able to do this. It's a browser thing.
  • -Confirmed
    +ThirdParty
#4 stephene*********@gmai***** (Google Code) (Is this you? Claim this profile.)
I think this would be worth doing, it's a very frequent need. I don't think it's due to a specific browser, most browsers will behave this way. There are various ways that the code could be made selectable, for example a toggle for numbers and a toggle for either side of the diff.
chipx86
#5 chipx86
You would think it's easy, but we've spent a lot of time on it, and there's no clean way of handling this. While it's possible to dynamically enable/disable selectability on elements, most browsers get it very wrong and are inconsistent with each other, particularly in tables.

Toggles could be an option, but then we're cluttering up the UI and requiring a lot of manual work just to select, and it'll probably just lead to people accidentally hiding parts of the UI and being confused. I don't feel that's an option we want to introduce.

In 2.0.x, you can view the full file's source by clicking the little icon that looks like a down arrow in a circle, right beside the revision. From there, you can copy and paste.
#6 jeff****@gmai***** (Google Code) (Is this you? Claim this profile.)
Have you tried javascript magic?

Specifically capture ctrl-c:
http://stackoverflow.com/questions/2903991/how-to-detect-ctrlv-ctrlc-using-javascript

Then manually manipulate the clipboard from javascript:
http://stackoverflow.com/questions/400212/how-to-copy-to-the-clipboard-in-javascript
http://stackoverflow.com/questions/7713182/copy-to-clipboard-for-all-browsers-using-javascript
david
#7 david
The clipboard APIs are quite new and not well supported across browsers. It also doesn't help with selecting the text in the first place.

If you want to take a crack at it, you're welcome to. We're happy to look at any patches for this.
chipx86
#8 chipx86
Been able to make this work with some of the latest browsers. There was more than clipboard API issues to tackle, but I figured it out. This will go into 2.0.9.
  • -ThirdParty
    +Confirmed
  • -Priority-Low
    +Priority-High
    +Milestone-Release2.0.x
  • +chipx86
chipx86
#9 chipx86
Fixed on release-2.0.x (6721e10). This will be part of 2.0.9.
  • -Confirmed
    +Fixed