Copy as GFM even when parts of other elements are selected
You can reproduce the bug this fixes right here in GitLab <9.3 by triple clicking my comment below, and either hitting r
or copy-pasting the selection into the GFM textarea below. Tested in Chrome.
As you'll see, using r
, nothing is inserted at all, and using copy/paste, the text is, but not as GFM!
The reason is that when you triple-click a block-level element (in Chrome at least), it actually selects that element, as well as an empty copy of the the element that follows it. In the example above, this roughly looks like:
<li class="note">
<div class="md">
<p>
Test comment with <strong>Markdown!</strong>
</p>
</div>
</li>
<li class="note"></li>
Before this change, our Copy-as-GFM logic would ignore this because of the if (documentFragment.querySelector('.md, .wiki')) return null;
check.
With this change, we handle this appropriately by seeing if the selection contains any .md, .wiki
elements and if so, only copying the text inside those, as GFM, so that the selection described above will result in the below, as expected:
Test comment with **Markdown!**
Merge request reports
Activity
added 1 commit
- 35c14a5a - Copy as GFM even when parts of other elements are selected
@mikegreiling can you please review?
assigned to @mikegreiling
LGTM
@filipa can you merge this?
assigned to @filipa
@DouweM can we add tests please? Thank you!
assigned to @DouweM
assigned to @filipa
Thank you @DouweM, the code LGTM but I can't reproduce either the bug or the fix
I click 3 times in the code block section and nothing gets either selected or copied, what am I doing wrong?
assigned to @DouweM
assigned to @filipa
added 276 commits
-
02bb62de...c013d23d - 274 commits from branch
master
- 78e7efae - Copy as GFM even when parts of other elements are selected
- f14bb942 - Add spec
-
02bb62de...c013d23d - 274 commits from branch
Thank you @DouweM
enabled an automatic merge when the pipeline for f14bb942 succeeds
mentioned in commit c846a832