@@ -5328,9 +5328,16 @@ func extractInlineAttachments(body string) (files []string, clean string) {
53285328 for _ , line := range strings .Split (body , "\n " ) {
53295329 trimmed := strings .TrimSpace (line )
53305330 var rest string
5331+ // Header form ("# [attach]") is what injectAttachmentsIntoPrelude
5332+ // writes for existing m.attachments on re-edit/spell/AI/continueDraft;
5333+ // it must round-trip back to a file attachment regardless of
5334+ // extension, otherwise an image attachment silently becomes an inline
5335+ // markdown image and disappears from m.attachments.
5336+ var header bool
53315337 switch {
53325338 case strings .HasPrefix (trimmed , "# [attach] " ):
53335339 rest = strings .TrimSpace (trimmed [len ("# [attach] " ):])
5340+ header = true
53345341 case strings .HasPrefix (trimmed , "[attach] " ):
53355342 rest = strings .TrimSpace (trimmed [len ("[attach] " ):])
53365343 default :
@@ -5340,10 +5347,9 @@ func extractInlineAttachments(body string) (files []string, clean string) {
53405347 if rest == "" {
53415348 continue
53425349 }
5343- if imageExts [strings .ToLower (filepath .Ext (rest ))] {
5350+ if ! header && imageExts [strings .ToLower (filepath .Ext (rest ))] {
53445351 // Inline: replace with markdown image ref so position is preserved.
5345- // Header-form "# [attach] /img" loses position (always at top), but
5346- // images placed via <leader>a inline use plain "[attach] /img" and
5352+ // Images placed via <leader>a inline use plain "[attach] /img" and
53475353 // render where the user put them.
53485354 kept = append (kept , "" )
53495355 } else {
0 commit comments