mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-22 04:11:12 +00:00
Modify the logic for appending the URL after uploading an image, placing the image URL after the cursor. (#2804)
This commit is contained in:
parent
5a82fa6a89
commit
f9b1096ded
1 changed files with 22 additions and 5 deletions
|
@ -460,12 +460,29 @@ export class MarkdownTextArea extends Component<
|
||||||
if (res.state === "success") {
|
if (res.state === "success") {
|
||||||
if (res.data.msg === "ok") {
|
if (res.data.msg === "ok") {
|
||||||
const imageMarkdown = `![](${res.data.url})`;
|
const imageMarkdown = `![](${res.data.url})`;
|
||||||
i.setState(({ content }) => ({
|
const textarea: HTMLTextAreaElement = document.getElementById(
|
||||||
content: content ? `${content}\n${imageMarkdown}` : imageMarkdown,
|
i.id,
|
||||||
}));
|
) as HTMLTextAreaElement;
|
||||||
|
const cursorPosition = textarea.selectionStart;
|
||||||
|
|
||||||
|
i.setState(({ content }) => {
|
||||||
|
const currentContent = content || "";
|
||||||
|
return {
|
||||||
|
content:
|
||||||
|
currentContent.slice(0, cursorPosition) +
|
||||||
|
imageMarkdown +
|
||||||
|
currentContent.slice(cursorPosition),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
i.contentChange();
|
i.contentChange();
|
||||||
const textarea: any = document.getElementById(i.id);
|
// Update cursor position to after the inserted image link
|
||||||
autosize.update(textarea);
|
setTimeout(() => {
|
||||||
|
textarea.selectionStart = cursorPosition + imageMarkdown.length;
|
||||||
|
textarea.selectionEnd = cursorPosition + imageMarkdown.length;
|
||||||
|
autosize.update(textarea);
|
||||||
|
}, 10);
|
||||||
|
|
||||||
pictrsDeleteToast(image.name, res.data.delete_url as string);
|
pictrsDeleteToast(image.name, res.data.delete_url as string);
|
||||||
} else if (res.data.msg === "too_large") {
|
} else if (res.data.msg === "too_large") {
|
||||||
toast(I18NextService.i18n.t("upload_too_large"), "danger");
|
toast(I18NextService.i18n.t("upload_too_large"), "danger");
|
||||||
|
|
Loading…
Reference in a new issue