Fix duplicate image display when sending multiple same-named images

Pasted screenshots all share the same filename (e.g. "image.png"), so the
placeholder substitution in _renderUserTextContent resolved every
placeholder to the FIRST matching inline image via find() - showing the
first image N times. Data itself was always correct (DB/agent received
all images; a refresh rendered them properly).

Match images consumingly (findIndex + splice on a copy) instead: labels
and inlineImages are built in the same order, so same-named images now
map one-to-one. Also fix the same latent issue in the legacy attachment
path in history.js (_autoLoadImageAttachments), keeping the shift()
fallback.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
MelekiandClaude Fable 5 committed 2026-06-11 17:14:21 +02:00
1 parent 4e41401f23
commit 483aa471a1
2 files changed
+16 -4

No files matched your search

+12 -2
View File
@@ -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 '<img class="inline-user-image" src="' + esc(img.dataUrl) + '" alt="' + esc(name) + '" title="' + esc(name) + '">';
}