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!**