Copying a rendered issue/comment will paste into GFM textareas as actual GFM
Tested in Chrome, Safari and Firefox. Works when copy-pasting and when using the r
shortcut to reply to selected text.
@rspeicher Can you review the Ruby?
@jschatz1 Can you review the JS?
/cc @smcgivern
Merge request reports
Activity
added 1 commit
- 3c472d74 - Copying a rendered issue/comment will paste into GFM textareas as actual GFM
- Resolved by Douwe Maan
added 1 commit
- dbfa58e2 - Copying a rendered issue/comment will paste into GFM textareas as actual GFM
- Resolved by Douwe Maan
- Resolved by Douwe Maan
- Resolved by Douwe Maan
- Resolved by Douwe Maan
- Resolved by Douwe Maan
- Resolved by Douwe Maan
- Resolved by Douwe Maan
- Resolved by Douwe Maan
- Resolved by Douwe Maan
- Resolved by Douwe Maan
- Resolved by Jacob Schatz
- Resolved by Douwe Maan
- Resolved by Douwe Maan
- Resolved by Douwe Maan
- Resolved by Douwe Maan
I am assuming you've read this right http://caniuse.com/#feat=clipboard. JIC
- Resolved by Douwe Maan
- Resolved by Douwe Maan
- Resolved by Douwe Maan
added 3 commits
changed milestone to %8.16
- Resolved by Douwe Maan
- Resolved by Douwe Maan
- Resolved by Douwe Maan
This is awesome! I see one regression: if I copy a long piece of text from a comment (longer than the comment textarea initially), the textarea doesn't resize, and isn't scrollable, until my next input in that textarea. That's not the case at the moment.
I also think this should only happen if you copy within a single GFM container. At the moment, copying across a comment boundary (for instance) will also copy the next commenter's avatar etc. as GFM. While that's cool, I think it's unexpected - but it's a pretty minor issue.
@smcgivern
I am g2g. ~~Feel free to merge when you are ready. ~~Nice job @DouweM, Mr JavaScript
Edited by Jacob Schatz- Resolved by Douwe Maan
- Resolved by Douwe Maan
document.querySelector
will run 40 times when you press copy. This is my only qualm.@jschatz1 I don't think that's true. We run
node.matches(selector)
1..40 times per node, to find the first selector that matches, and this is always in the context of a small document fragment (covering the selected text), not the full document. The performance impact in such a small document is negligible.
I see one regression: if I copy a long piece of text from a comment (longer than the comment textarea initially), the textarea doesn't resize, and isn't scrollable, until my next input in that textarea.
@smcgivern Yeah, I saw that too. I added
$(target).trigger('input');
when inserting the text, but that doesn't help.@jschatz1 Any ideas?Fixed it!I also think this should only happen if you copy within a single GFM container. At the moment, copying across a comment boundary (for instance) will also copy the next commenter's avatar etc. as GFM. While that's cool, I think it's unexpected - but it's a pretty minor issue.
Yep, saw that too. I'll see if there's anything I can do about it! Edit: Done!
Ah, one more thing: could HTML elements that are allowed in Markdown, but don't have special syntax (like
kbd
), be passed through usingouterHTML
or whatever? We'd still sanitize it when rendering, after all.Let me have a look at that :) Edit: Done!
Edited by Douwe Maanmentioned in issue #26860 (closed)
- Resolved by Douwe Maan
@smcgivern Would you like to review the backend?
assigned to @smcgivern
added 173 commits
-
f928e19c...52762df2 - 172 commits from branch
master
- 2b37e4c1 - Merge branch 'master' into copy-as-md
-
f928e19c...52762df2 - 172 commits from branch
@DouweM Did you check this for iphone and android. I see a few JS things that aren't supported on mobile browsers that could have unforseen results. I can't check right now. If not we need to gracefully degrade.
@DouweM handing over frontend reviewing to @mikegreiling
Edited by Jacob Schatzchanged milestone to %8.17
I'll be going to go through the code changes in more depth soon, but just playing around with it a bit right now.
First of all, awesome feature
. I can't wait to get this one in.That said, I've noticed some small issues.
- I couldn't get tables to copy/paste quite right.
- Also lists which contain blockquotes or other indented items were somewhat flaky.
source:
copypasta:
result:
Edited by username-removed-636429@mikegreiling Good catches! But I'm a perfectionist so I'll fix the table and nested blockquote cases :D
assigned to @DouweM
Here's the source markdown from my test:
## Test header 1 Test header 2 ========== here's a paragraph of text and here's some attachments:  * list item 1 * list [item 2](http://google.com/) * list item 3 * list item 4 ```javascript function helloWorld () { alert("hello world!"); } ``` | | x | y | |-------|-------|-------| | a | 1 | 0 | | b | 0 | 1 | here's another thingie > and here's a block quote! * here's a list item * and another list item > with a block quote inside it!! * wut??
@mikegreiling All fixed!
added 1 commit
- d89f5616 - Improve support for linebreaks, tables and nested blockquotes in lists
added 1 commit
- bd2880bb - Improve handling of code blocks containing triple backticks
assigned to @mikegreiling
- Resolved by username-removed-443319
- Resolved by Douwe Maan
added 262 commits
-
bd2880bb...8c9a06c3 - 260 commits from branch
master
- 79440890 - Merge branch 'master' into copy-as-md
- 43dc6263 - Run tests in a single browser session
-
bd2880bb...8c9a06c3 - 260 commits from branch
assigned to @smcgivern
@DouweM this is good to go, but there are conflicts and I'm not sure how they should be resolved. @mikegreiling can you help, please? Once those are fixing, @DouweM feel free to set MWPS!
assigned to @mikegreiling
@smcgivern and @DouweM please wait to get the green light from @mikegreiling before merging.
Edited by Jacob Schatzadded 87 commits
-
43dc6263...b55c1bc4 - 86 commits from branch
master
- 21755ac9 - Merge branch 'master' into copy-as-md
-
43dc6263...b55c1bc4 - 86 commits from branch
Alright, this all LGTM
There are a handful of eslint violations to fix up:
no-param-reassign
on three lines, and once case ofno-multiple-empty-lines
.I wish we didn't need to disable so many linter rules on this file, but the ones you've disabled seem sensible for now.
The IE11 thing is fine. It gracefully degrades to the normal copy/paste behavior when
Event.clipboardData
isn't found. I understand IE exposes this asdocument.clipboardData
but it has other compatibility issues as well and I don't think it would be worth the time to get this running in a legacy browser.Should be good to merge once the linter errors are addressed and once the builds pass.
Awesome work!
I've definitely encountered times where this would have been helpful in the past... I'm excited to see this one merged.assigned to @DouweM
@mikegreiling eslint satisfied :) Merge if you're happy!
assigned to @mikegreiling
enabled an automatic merge when the pipeline for 6c2d8f35 succeeds
mentioned in commit a24e9a0e
mentioned in merge request !9080 (merged)
mentioned in merge request !9874 (merged)
mentioned in merge request !9876 (merged)
mentioned in issue #29732 (closed)
mentioned in issue #29788 (moved)
mentioned in issue #31193 (closed)
mentioned in issue #32546 (moved)
mentioned in issue gitlab#9964