Copy as GFM even when parts of other elements are selected
This commit is contained in:
parent
c013d23d63
commit
78e7efaed0
|
@ -330,10 +330,26 @@ class CopyAsGFM {
|
|||
}
|
||||
|
||||
static transformGFMSelection(documentFragment) {
|
||||
// If the documentFragment contains more than just Markdown, don't copy as GFM.
|
||||
if (documentFragment.querySelector('.md, .wiki')) return null;
|
||||
const gfmEls = documentFragment.querySelectorAll('.md, .wiki');
|
||||
switch (gfmEls.length) {
|
||||
case 0: {
|
||||
return documentFragment;
|
||||
}
|
||||
case 1: {
|
||||
return gfmEls[0];
|
||||
}
|
||||
default: {
|
||||
const allGfmEl = document.createElement('div');
|
||||
|
||||
return documentFragment;
|
||||
for (let i = 0; i < gfmEls.length; i += 1) {
|
||||
const lineEl = gfmEls[i];
|
||||
allGfmEl.appendChild(lineEl);
|
||||
allGfmEl.appendChild(document.createTextNode('\n\n'));
|
||||
}
|
||||
|
||||
return allGfmEl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static transformCodeSelection(documentFragment) {
|
||||
|
|
|
@ -38,7 +38,7 @@ import './shortcuts_navigation';
|
|||
}
|
||||
|
||||
ShortcutsIssuable.prototype.replyWithSelectedText = function() {
|
||||
var quote, documentFragment, selected, separator;
|
||||
var quote, documentFragment, el, selected, separator;
|
||||
var replyField = $('.js-main-target-form #note_note');
|
||||
|
||||
documentFragment = window.gl.utils.getSelectedFragment();
|
||||
|
@ -47,10 +47,8 @@ import './shortcuts_navigation';
|
|||
return;
|
||||
}
|
||||
|
||||
// If the documentFragment contains more than just Markdown, don't copy as GFM.
|
||||
if (documentFragment.querySelector('.md, .wiki')) return;
|
||||
|
||||
selected = window.gl.CopyAsGFM.nodeToGFM(documentFragment);
|
||||
el = window.gl.CopyAsGFM.transformGFMSelection(documentFragment.cloneNode(true));
|
||||
selected = window.gl.CopyAsGFM.nodeToGFM(el);
|
||||
|
||||
if (selected.trim() === "") {
|
||||
return;
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
title: Copy as GFM even when parts of other elements are selected
|
||||
merge_request:
|
||||
author:
|
Loading…
Reference in New Issue