update textarea height and refocus when attaching files
also fix extra newline when pasting image into textarea
This commit is contained in:
parent
2b934a7f43
commit
ee65f5eecb
2 changed files with 11 additions and 4 deletions
|
@ -130,13 +130,15 @@ window.DropzoneInput = (function() {
|
|||
var afterSelection, beforeSelection, caretEnd, caretStart, textEnd;
|
||||
var formattedText = text;
|
||||
if (shouldPad) formattedText += "\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) {
|
||||
|
@ -180,7 +182,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) {
|
||||
|
@ -215,6 +217,7 @@ window.DropzoneInput = (function() {
|
|||
form.find(".markdown-selector").click(function(e) {
|
||||
e.preventDefault();
|
||||
$(this).closest('.gfm-form').find('.div-dropzone').click();
|
||||
form_textarea.focus();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
4
changelogs/unreleased/30008-textarea-focus.yml
Normal file
4
changelogs/unreleased/30008-textarea-focus.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
title: refocus textarea after attaching a file
|
||||
merge_request:
|
||||
author:
|
Loading…
Reference in a new issue