Skip to content

Commit

Permalink
fix image deletion
Browse files Browse the repository at this point in the history
remove img markdown from textarea after deletion of image
minor cleanup
  • Loading branch information
thooyork committed Jun 13, 2024
1 parent 7f6b738 commit a43f944
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion client/src/views/PostFormView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
</div>
<Suspense v-for="hash in Object.keys(files)" v-bind:key="hash">
<ImagePreview :value="files[hash]" :hash="hash" @paste="pasteImageFileToMarkdown($event, 'afterCursor')"
@delete="delete files[hash]">
@delete="removeImageFileFromMarkdown(files[hash]); delete files[hash]">
</ImagePreview>
</Suspense>
</div>
Expand Down Expand Up @@ -343,6 +343,15 @@ const pasteImageFileToMarkdown = (markdown: string, insertPosition: SupportedIns
form.markdown = insertIntoTextarea(markdown, markdownArea.value as unknown as HTMLTextAreaElement, insertPosition);
};
const removeImageFileFromMarkdown = (file: File) => {
const markDownBeforeRemove = form.markdown;
const strToRemove = `![${file.name}](${Object.keys(files).find((key) => files[key] === file)})`;
// Giving the textarea time to update the value, otherwise the last image deletion will not update the preview!
setTimeout(() => {
form.markdown = markDownBeforeRemove.replace(strToRemove, "");
}, 0);
}
const dropMarkdown = (evt: DragEvent) => {
const items = evt.dataTransfer?.items;
const textArea = evt.target as HTMLTextAreaElement;
Expand Down

0 comments on commit a43f944

Please sign in to comment.