From 4fd8d8e0eedabc955653884ee87e49e05bcce404 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Tue, 13 Aug 2024 23:35:49 +0300 Subject: [PATCH] Add swipes when using paintbrush --- .../scripts/extensions/stable-diffusion/index.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/public/scripts/extensions/stable-diffusion/index.js b/public/scripts/extensions/stable-diffusion/index.js index 4edb1bacf..fe81d722e 100644 --- a/public/scripts/extensions/stable-diffusion/index.js +++ b/public/scripts/extensions/stable-diffusion/index.js @@ -3617,10 +3617,23 @@ async function sdMessageButton(e) { function saveGeneratedImage(prompt, image, generationType, negative) { // Some message sources may not create the extra object - if (typeof message.extra !== 'object') { + if (typeof message.extra !== 'object' || message.extra === null) { message.extra = {}; } + // Add image to the swipe list if it's not already there + if (!Array.isArray(message.extra.image_swipes)) { + message.extra.image_swipes = []; + } + + const swipes = message.extra.image_swipes; + + if (message.extra.image && !swipes.includes(message.extra.image)) { + swipes.push(message.extra.image); + } + + swipes.push(image); + // If already contains an image and it's not inline - leave it as is message.extra.inline_image = message.extra.image && !message.extra.inline_image ? false : true; message.extra.image = image;