From 115d1afeb386d2b1fef4ca437fafd8227d72c0ad Mon Sep 17 00:00:00 2001 From: "Luke \"Jared\" Bennett" Date: Fri, 7 Apr 2017 17:29:08 +0100 Subject: [PATCH] Only add newlines for multiple uploads --- app/assets/javascripts/dropzone_input.js | 10 +++++++--- .../remove-double-newline-for-single-attachments.yml | 4 ++++ spec/features/issues_spec.rb | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 changelogs/unreleased/remove-double-newline-for-single-attachments.yml diff --git a/app/assets/javascripts/dropzone_input.js b/app/assets/javascripts/dropzone_input.js index f2963a5eb19..df0e3f46827 100644 --- a/app/assets/javascripts/dropzone_input.js +++ b/app/assets/javascripts/dropzone_input.js @@ -66,7 +66,10 @@ window.DropzoneInput = (function() { form_textarea.focus(); }, success: function(header, response) { - pasteText(response.link.markdown); + const processingFileCount = this.getQueuedFiles().length + this.getUploadingFiles().length; + const shouldPad = processingFileCount >= 1; + + pasteText(response.link.markdown, shouldPad); }, error: function(temp) { var checkIfMsgExists, errorAlert; @@ -123,9 +126,10 @@ window.DropzoneInput = (function() { } return false; }; - pasteText = function(text) { + pasteText = function(text, shouldPad) { var afterSelection, beforeSelection, caretEnd, caretStart, textEnd; - var formattedText = text + "\n\n"; + var formattedText = text; + if (shouldPad) formattedText += "\n\n"; caretStart = $(child)[0].selectionStart; caretEnd = $(child)[0].selectionEnd; textEnd = $(child).val().length; diff --git a/changelogs/unreleased/remove-double-newline-for-single-attachments.yml b/changelogs/unreleased/remove-double-newline-for-single-attachments.yml new file mode 100644 index 00000000000..98a28e1ede1 --- /dev/null +++ b/changelogs/unreleased/remove-double-newline-for-single-attachments.yml @@ -0,0 +1,4 @@ +--- +title: Only add newlines between multiple uploads +merge_request: 10545 +author: diff --git a/spec/features/issues_spec.rb b/spec/features/issues_spec.rb index e3213d24f6a..362d167befa 100644 --- a/spec/features/issues_spec.rb +++ b/spec/features/issues_spec.rb @@ -601,10 +601,10 @@ describe 'Issues', feature: true do expect(page.find_field("issue_description").value).to have_content 'banana_sample' end - it 'adds double newline to end of attachment markdown' do + it "doesn't add double newline to end of a single attachment markdown" do dropzone_file Rails.root.join('spec', 'fixtures', 'banana_sample.gif') - expect(page.find_field("issue_description").value).to match /\n\n$/ + expect(page.find_field("issue_description").value).not_to match /\n\n$/ end end