upload: Append file markdown to textarea when placeholder is missing.

Fixes #26037.
This commit is contained in:
evykassirer
2023-06-25 17:02:19 -07:00
committed by Tim Abbott
parent 46b582689a
commit cbd4aad0a5
3 changed files with 14 additions and 3 deletions

View File

@@ -189,7 +189,9 @@ export function replace_syntax(old_syntax, new_syntax, $textarea = $("#compose-t
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Description
// for details.
const old_text = $textarea.val();
replace($textarea[0], old_syntax, () => new_syntax, "after-replacement");
const new_text = $textarea.val();
// When replacing content in a textarea, we need to move the cursor
// to preserve its logical position if and only if the content we
@@ -207,6 +209,9 @@ export function replace_syntax(old_syntax, new_syntax, $textarea = $("#compose-t
// Otherwise we simply restore it to it's original position
$textarea.caret(prev_caret);
}
// Return if anything was actually replaced.
return old_text !== new_text;
}
export function compute_placeholder_text(opts) {

View File

@@ -341,12 +341,17 @@ export function setup_upload(config) {
const split_url = url.split("/");
const filename = split_url.at(-1);
const filename_url = "[" + filename + "](" + url + ")";
compose_ui.replace_syntax(
const $text_area = get_item("textarea", config);
const replacement_successful = compose_ui.replace_syntax(
get_translated_status(file),
filename_url,
get_item("textarea", config),
$text_area,
);
compose_ui.autosize_textarea(get_item("textarea", config));
if (!replacement_successful) {
compose_ui.insert_syntax_and_focus(filename_url, $text_area);
}
compose_ui.autosize_textarea($text_area);
// The uploaded files should be removed since uppy doesn't allow files in the store
// to be re-uploaded again.

View File

@@ -492,6 +492,7 @@ test("copy_paste", ({override, override_rewire}) => {
test("uppy_events", ({override_rewire, mock_template}) => {
$("#compose_banners .upload_banner .moving_bar").css = () => {};
$("#compose_banners .upload_banner").length = 0;
override_rewire(compose_ui, "smart_insert_inline", () => {});
const callbacks = {};
let state = {};