From 83375c5eaf0323d7c3010c3e6d894f209487a9ae Mon Sep 17 00:00:00 2001 From: Filipa Lacerda Date: Wed, 19 Apr 2017 10:30:59 +0000 Subject: Merge branch '30008-textarea-focus' into 'master' update textarea height and refocus when attaching files Closes #30008 See merge request !10300 --- app/assets/javascripts/dropzone_input.js | 11 +++++++---- changelogs/unreleased/30008-textarea-focus.yml | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 changelogs/unreleased/30008-textarea-focus.yml diff --git a/app/assets/javascripts/dropzone_input.js b/app/assets/javascripts/dropzone_input.js index f2963a5eb19..69bf9c4b29e 100644 --- a/app/assets/javascripts/dropzone_input.js +++ b/app/assets/javascripts/dropzone_input.js @@ -126,13 +126,15 @@ window.DropzoneInput = (function() { pasteText = function(text) { var afterSelection, beforeSelection, caretEnd, caretStart, textEnd; var formattedText = text + "\n\n"; - caretStart = $(child)[0].selectionStart; - caretEnd = $(child)[0].selectionEnd; + const textarea = child.get(0); + caretStart = textarea.selectionStart; + caretEnd = textarea.selectionEnd; textEnd = $(child).val().length; beforeSelection = $(child).val().substring(0, caretStart); afterSelection = $(child).val().substring(caretEnd, textEnd); $(child).val(beforeSelection + formattedText + afterSelection); - child.get(0).setSelectionRange(caretStart + formattedText.length, caretEnd + formattedText.length); + textarea.setSelectionRange(caretStart + formattedText.length, caretEnd + formattedText.length); + textarea.style.height = `${textarea.scrollHeight}px`; return form_textarea.trigger("input"); }; getFilename = function(e) { @@ -176,7 +178,7 @@ window.DropzoneInput = (function() { }; insertToTextArea = function(filename, url) { return $(child).val(function(index, val) { - return val.replace("{{" + filename + "}}", url + "\n"); + return val.replace("{{" + filename + "}}", url); }); }; appendToTextArea = function(url) { @@ -211,6 +213,7 @@ window.DropzoneInput = (function() { form.find(".markdown-selector").click(function(e) { e.preventDefault(); $(this).closest('.gfm-form').find('.div-dropzone').click(); + form_textarea.focus(); }); } diff --git a/changelogs/unreleased/30008-textarea-focus.yml b/changelogs/unreleased/30008-textarea-focus.yml new file mode 100644 index 00000000000..91837bbf96e --- /dev/null +++ b/changelogs/unreleased/30008-textarea-focus.yml @@ -0,0 +1,4 @@ +--- +title: refocus textarea after attaching a file +merge_request: +author: -- cgit v1.2.1