diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-01-16 15:27:05 -0500 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-01-16 16:14:18 -0500 |
commit | dbfa58e2da7f939734eee5a599b4014d6095dde3 (patch) | |
tree | 44b7265dc7a20fcd1d4cc8f5782514837e959f17 /app/assets/javascripts/shortcuts_issuable.js | |
parent | 142be72a2aa6920fa60cc267737f2e702fdeae12 (diff) | |
download | gitlab-ce-dbfa58e2da7f939734eee5a599b4014d6095dde3.tar.gz |
Copying a rendered issue/comment will paste into GFM textareas as actual GFM
Diffstat (limited to 'app/assets/javascripts/shortcuts_issuable.js')
-rw-r--r-- | app/assets/javascripts/shortcuts_issuable.js | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/app/assets/javascripts/shortcuts_issuable.js b/app/assets/javascripts/shortcuts_issuable.js index b892fbc3393..426821873d7 100644 --- a/app/assets/javascripts/shortcuts_issuable.js +++ b/app/assets/javascripts/shortcuts_issuable.js @@ -39,29 +39,33 @@ } ShortcutsIssuable.prototype.replyWithSelectedText = function() { - var quote, replyField, selected, separator; - if (window.getSelection) { - selected = window.getSelection().toString(); - replyField = $('.js-main-target-form #note_note'); - if (selected.trim() === "") { - return; - } - // Put a '>' character before each non-empty line in the selection - quote = _.map(selected.split("\n"), function(val) { - if (val.trim() !== '') { - return "> " + val + "\n"; - } - }); - // If replyField already has some content, add a newline before our quote - separator = replyField.val().trim() !== "" && "\n" || ''; - replyField.val(function(_, current) { - return current + separator + quote.join('') + "\n"; - }); - // Trigger autosave for the added text - replyField.trigger('input'); - // Focus the input field - return replyField.focus(); + var quote, replyField, selectedDocument, selected, selection, separator; + if (!window.getSelection) return; + + selection = window.getSelection(); + if (!selection.rangeCount || selection.rangeCount === 0) return; + + selectedDocument = selection.getRangeAt(0).cloneContents(); + if (!selectedDocument) return; + + selected = window.gl.CopyAsGFM.nodeToGFM(selectedDocument); + + replyField = $('.js-main-target-form #note_note'); + if (selected.trim() === "") { + return; } + quote = _.map(selected.split("\n"), function(val) { + return "> " + val + "\n"; + }); + // If replyField already has some content, add a newline before our quote + separator = replyField.val().trim() !== "" && "\n" || ''; + replyField.val(function(_, current) { + return current + separator + quote.join('') + "\n"; + }); + // Trigger autosave for the added text + replyField.trigger('input'); + // Focus the input field + return replyField.focus(); }; ShortcutsIssuable.prototype.editIssue = function() { |