diff --git a/wwwroot/js/bubbles.js b/wwwroot/js/bubbles.js index fdabcb8..0e5ba61 100644 --- a/wwwroot/js/bubbles.js +++ b/wwwroot/js/bubbles.js @@ -53,11 +53,21 @@ function _renderUserTextContent(container, raw, inlineImages) { // Markdown rendern let html = renderMarkdown(mdText); - // Bild-Platzhalter durch Inline-Bilder ersetzen + // Bild-Platzhalter durch Inline-Bilder ersetzen. + // WICHTIG: Gematchte Bilder werden VERBRAUCHT (splice) statt nur per find() gesucht – + // bei mehreren Bildern mit identischem Dateinamen (z.B. eingefügte Screenshots heißen + // alle "image.png") würde find() sonst für jeden Platzhalter immer das ERSTE Bild + // liefern → erstes Bild N-fach angezeigt. Labels und inlineImages entstehen in + // derselben Reihenfolge, daher ordnet das Verbrauchen sie korrekt der Reihe nach zu. + const remainingInline = inlineImages ? inlineImages.slice() : null; html = html.replace(/%%IMGREF(\d+)%%/g, function(m, idx) { const name = imageRefs[parseInt(idx)]; // Wenn Inline-Bild-Daten vorhanden (beim Senden), direkt anzeigen - const img = inlineImages && inlineImages.find(function(i) { return i.name === name; }); + let img = null; + if (remainingInline) { + const i = remainingInline.findIndex(function(x) { return x.name === name; }); + if (i !== -1) img = remainingInline.splice(i, 1)[0]; + } if (img) { return '' + esc(name) + ''; } diff --git a/wwwroot/js/history.js b/wwwroot/js/history.js index 749fb74..7861037 100644 --- a/wwwroot/js/history.js +++ b/wwwroot/js/history.js @@ -37,8 +37,10 @@ async function _autoLoadImageAttachments(messageId) { placeholders.forEach(function(ph) { const filename = ph.dataset.filename; - // Bild anhand Dateiname zuordnen, oder der Reihe nach - const att = imageAtts.find(function(a) { return a.fileName === filename; }) || imageAtts.shift(); + // Bild anhand Dateiname zuordnen (verbrauchend via splice – bei identischen + // Dateinamen würde find() sonst immer das erste Bild liefern), oder der Reihe nach + const idx = imageAtts.findIndex(function(a) { return a.fileName === filename; }); + const att = idx !== -1 ? imageAtts.splice(idx, 1)[0] : imageAtts.shift(); if (att) { const img = document.createElement('img'); img.className = 'inline-user-image';