diff --git a/public/index.html b/public/index.html
index ad52d580f..7f039ad7d 100644
--- a/public/index.html
+++ b/public/index.html
@@ -5686,10 +5686,11 @@
-
+
+
diff --git a/public/script.js b/public/script.js
index 64e917a93..4be05d0dc 100644
--- a/public/script.js
+++ b/public/script.js
@@ -2079,14 +2079,23 @@ export function updateMessageBlock(messageId, message) {
appendMediaToMessage(message, messageElement);
}
-export function appendMediaToMessage(mes, messageElement) {
+/**
+ * Appends image or file to the message element.
+ * @param {object} mes Message object
+ * @param {JQuery
} messageElement Message element
+ * @param {boolean} [adjustScroll=true] Whether to adjust the scroll position after appending the media
+ */
+export function appendMediaToMessage(mes, messageElement, adjustScroll = true) {
// Add image to message
if (mes.extra?.image) {
const chatHeight = $('#chat').prop('scrollHeight');
const image = messageElement.find('.mes_img');
const text = messageElement.find('.mes_text');
const isInline = !!mes.extra?.inline_image;
- image.on('load', function () {
+ image.off('load').on('load', function () {
+ if (!adjustScroll) {
+ return;
+ }
const scrollPosition = $('#chat').scrollTop();
const newChatHeight = $('#chat').prop('scrollHeight');
const diff = newChatHeight - chatHeight;
@@ -5636,7 +5645,7 @@ export async function renameCharacter(name = null, { silent = false, renameChats
}
}
catch (error) {
- // Reloading to prevent data corruption
+ // Reloading to prevent data corruption
if (!silent) await callPopup('Something went wrong. The page will be reloaded.', 'text');
else toastr.error('Something went wrong. The page will be reloaded.', 'Rename Character');
diff --git a/public/scripts/extensions/caption/index.js b/public/scripts/extensions/caption/index.js
index c5797fad6..60bc35078 100644
--- a/public/scripts/extensions/caption/index.js
+++ b/public/scripts/extensions/caption/index.js
@@ -1,6 +1,6 @@
import { ensureImageFormatSupported, getBase64Async, isTrueBoolean, saveBase64AsFile } from '../../utils.js';
import { getContext, getApiUrl, doExtrasFetch, extension_settings, modules, renderExtensionTemplateAsync } from '../../extensions.js';
-import { callPopup, eventSource, event_types, getRequestHeaders, saveSettingsDebounced, substituteParamsExtended } from '../../../script.js';
+import { appendMediaToMessage, callPopup, eventSource, event_types, getRequestHeaders, saveChatConditional, saveSettingsDebounced, substituteParamsExtended } from '../../../script.js';
import { getMessageTimeStamp } from '../../RossAscends-mods.js';
import { SECRET_KEYS, secret_state } from '../../secrets.js';
import { getMultimodalCaption } from '../shared.js';
@@ -514,6 +514,15 @@ jQuery(async function () {
eventSource.on(event_types.MESSAGE_SENT, onMessageEvent);
eventSource.on(event_types.MESSAGE_FILE_EMBEDDED, onMessageEvent);
+ $(document).on('click', '.mes_img_caption', async function () {
+ const messageBlock = $(this).closest('.mes');
+ const index = Number(messageBlock.attr('mesid'));
+ const data = getContext().chat[index];
+ await captionExistingMessage(data);
+ appendMediaToMessage(data, messageBlock, false);
+ await saveChatConditional();
+ });
+
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'caption',
callback: captionCommandCallback,
returns: 'caption',
@@ -548,4 +557,6 @@ jQuery(async function () {
`,
}));
+
+ document.body.classList.add('caption');
});
diff --git a/public/style.css b/public/style.css
index 101fe4184..7f1aa081a 100644
--- a/public/style.css
+++ b/public/style.css
@@ -4481,7 +4481,8 @@ a {
}
.mes_img_controls .right_menu_button {
- filter: brightness(80%);
+ filter: brightness(90%);
+ text-shadow: 1px 1px var(--SmartThemeShadowColor) !important;
padding: 1px;
height: 1.25em;
width: 1.25em;
@@ -4506,6 +4507,10 @@ a {
display: flex;
}
+body:not(.caption) .mes_img_caption {
+ display: none;
+}
+
.img_enlarged_holder {
/* Scaling via flex-grow and object-fit only works if we have some kind of base-height set */
min-height: 120px;