summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorFilipa Lacerda <filipa@gitlab.com>2017-05-24 20:45:55 +0000
committerFilipa Lacerda <filipa@gitlab.com>2017-05-24 20:45:55 +0000
commitc846a8329ab24b551c1e6cc899434c0802769137 (patch)
treee7852c6ef3e165bc4924bc97847e00f336b1ae4e /app
parentc013d23d6320487cf293891f7c6b213cab816980 (diff)
parentf14bb942538c28850d4d971be48a0acfb06e1ad3 (diff)
downloadgitlab-ce-c846a8329ab24b551c1e6cc899434c0802769137.tar.gz
Merge branch 'dm-copy-gfm-when-parts-of-other-elements-are-selected' into 'master'
Copy as GFM even when parts of other elements are selected See merge request !11521
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/copy_as_gfm.js22
-rw-r--r--app/assets/javascripts/shortcuts_issuable.js8
2 files changed, 22 insertions, 8 deletions
diff --git a/app/assets/javascripts/copy_as_gfm.js b/app/assets/javascripts/copy_as_gfm.js
index b479e854f7c..ba9d9a3e1f7 100644
--- a/app/assets/javascripts/copy_as_gfm.js
+++ b/app/assets/javascripts/copy_as_gfm.js
@@ -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) {
diff --git a/app/assets/javascripts/shortcuts_issuable.js b/app/assets/javascripts/shortcuts_issuable.js
index b07b3a4d3a5..dace03554e8 100644
--- a/app/assets/javascripts/shortcuts_issuable.js
+++ b/app/assets/javascripts/shortcuts_issuable.js
@@ -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;