Skip to content
Snippets Groups Projects
Commit 78e7efae authored by Douwe Maan's avatar Douwe Maan
Browse files

Copy as GFM even when parts of other elements are selected

parent c013d23d
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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');
for (let i = 0; i < gfmEls.length; i += 1) {
const lineEl = gfmEls[i];
allGfmEl.appendChild(lineEl);
allGfmEl.appendChild(document.createTextNode('\n\n'));
}
 
return documentFragment;
return allGfmEl;
}
}
}
 
static transformCodeSelection(documentFragment) {
Loading
Loading
Loading
Loading
@@ -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();
Loading
Loading
@@ -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;
Loading
Loading
---
title: Copy as GFM even when parts of other elements are selected
merge_request:
author:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment