From 8ffc0b683ac31ca4f1e709b913fc8bc950335828 Mon Sep 17 00:00:00 2001
From: Vyacheslav Tumanov <me@slavatumanov.me>
Date: Thu, 23 Mar 2023 11:07:26 +0500
Subject: [PATCH] TSK-858: Send picture without text as comment for issues
 (#2793)

Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me>
---
 .../text-editor/src/components/ReferenceInput.svelte   |  8 +++++---
 .../text-editor/src/components/StyledTextEditor.svelte |  3 +++
 packages/text-editor/src/components/TextEditor.svelte  |  6 ++----
 .../src/components/AccordionEditor.svelte              | 10 +++++++---
 4 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/packages/text-editor/src/components/ReferenceInput.svelte b/packages/text-editor/src/components/ReferenceInput.svelte
index cdb53e0e42..ac12dd16ca 100644
--- a/packages/text-editor/src/components/ReferenceInput.svelte
+++ b/packages/text-editor/src/components/ReferenceInput.svelte
@@ -285,9 +285,11 @@
         bind:isEmpty
         bind:this={textEditor}
         on:content={(ev) => {
-          dispatch('message', ev.detail)
-          content = ''
-          textEditor.clear()
+          if (!isEmpty || haveAttachment) {
+            dispatch('message', ev.detail)
+            content = ''
+            textEditor.clear()
+          }
         }}
         extensions={editorExtensions}
         on:selection-update={updateFormattingState}
diff --git a/packages/text-editor/src/components/StyledTextEditor.svelte b/packages/text-editor/src/components/StyledTextEditor.svelte
index 697021327d..456aedf3ff 100644
--- a/packages/text-editor/src/components/StyledTextEditor.svelte
+++ b/packages/text-editor/src/components/StyledTextEditor.svelte
@@ -70,6 +70,7 @@
   export let full = false
 
   let textEditor: TextEditor
+  let isEmpty = true
 
   export function submit (): void {
     textEditor.submit()
@@ -487,6 +488,7 @@
             bind:content
             {placeholder}
             bind:this={textEditor}
+            bind:isEmpty
             on:value
             on:content={(ev) => {
               dispatch('message', ev.detail)
@@ -504,6 +506,7 @@
           bind:content
           {placeholder}
           bind:this={textEditor}
+          bind:isEmpty
           on:value
           on:content={(ev) => {
             dispatch('message', ev.detail)
diff --git a/packages/text-editor/src/components/TextEditor.svelte b/packages/text-editor/src/components/TextEditor.svelte
index 758788f8fc..bed7344167 100644
--- a/packages/text-editor/src/components/TextEditor.svelte
+++ b/packages/text-editor/src/components/TextEditor.svelte
@@ -50,10 +50,8 @@
     if (editor) editor.setEditable(editable)
   }
   export function submit (): void {
-    if (!editor.isEmpty) {
-      content = editor.getHTML()
-      dispatch('content', content)
-    }
+    content = editor.getHTML()
+    dispatch('content', content)
   }
   export function setContent (newContent: string): void {
     if (content !== newContent) {
diff --git a/plugins/attachment-resources/src/components/AccordionEditor.svelte b/plugins/attachment-resources/src/components/AccordionEditor.svelte
index 2a09e98240..a9bf20ceff 100644
--- a/plugins/attachment-resources/src/components/AccordionEditor.svelte
+++ b/plugins/attachment-resources/src/components/AccordionEditor.svelte
@@ -35,6 +35,7 @@
   const attachments: AttachmentStyledBox[] = []
   const edits: TextEditor[] = []
   let hasAttachments: boolean = false
+  const isEmpty: boolean[] = [true]
   const expanded: boolean[] = []
   items.forEach(() => expanded.push(false))
 
@@ -86,13 +87,16 @@
             <TextEditor
               bind:content={item.content}
               bind:this={edits[i]}
+              bind:isEmpty={isEmpty[i]}
               on:value={(ev) => {
                 dispatch('update', { item, value: ev.detail })
               }}
               on:content={(ev) => {
-                items[i].content = ev.detail
-                dispatch('update', { item, value: ev.detail })
-                flip(i)
+                if (!isEmpty[i]) {
+                  items[i].content = ev.detail
+                  dispatch('update', { item, value: ev.detail })
+                  flip(i)
+                }
               }}
               on:blur={() => dispatch('blur', item)}
             />