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:
1 parent
4e41401f23
commit
483aa471a1
2 files changed
+16
-4
No files matched your search
+12
-2
@@ -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) + '">';
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
Reference in new issue
Block a user