From 3bbb2c3e80d6a2c99839640907fe46fd22ade2e8 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 22 Mar 2025 13:56:29 +0200 Subject: [PATCH] feat(mermaid): save SVG attachment only when needed --- .../type_widgets/abstract_svg_split_type_widget.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/public/app/widgets/type_widgets/abstract_svg_split_type_widget.ts b/src/public/app/widgets/type_widgets/abstract_svg_split_type_widget.ts index 50df1a09e..b0a4cd69d 100644 --- a/src/public/app/widgets/type_widgets/abstract_svg_split_type_widget.ts +++ b/src/public/app/widgets/type_widgets/abstract_svg_split_type_widget.ts @@ -50,11 +50,20 @@ export default abstract class AbstractSvgSplitTypeWidget extends AbstractSplitTy const blob = await note?.getBlob(); const content = blob?.content || ""; this.onContentChanged(content, true); + + // Save the SVG when entering a note only when it does not have an attachment. + this.note?.getAttachments().then((attachments) => { + const attachmentName = `${this.attachmentName}.svg`; + if (!attachments.find((a) => a.title === attachmentName)) { + this.#saveSvg(); + } + }); } getData(): { content: string; } { const data = super.getData(); this.onContentChanged(data.content, false); + this.#saveSvg(); return data; } @@ -89,7 +98,6 @@ export default abstract class AbstractSvgSplitTypeWidget extends AbstractSplitTy this.$renderContainer.html(svg); await this.#setupPanZoom(!recenter); - this.#saveSvg(); } #saveSvg() {