Add button to re-caption message image
This commit is contained in:
parent
7149f46c9a
commit
f181d1a847
|
@ -5686,10 +5686,11 @@
|
||||||
<div class="mes_edit_cancel menu_button fa-solid fa-xmark" title="Cancel" data-i18n="[title]Cancel"></div>
|
<div class="mes_edit_cancel menu_button fa-solid fa-xmark" title="Cancel" data-i18n="[title]Cancel"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class=mes_text></div>
|
<div class="mes_text"></div>
|
||||||
<div class="mes_img_container">
|
<div class="mes_img_container">
|
||||||
<div class="mes_img_controls">
|
<div class="mes_img_controls">
|
||||||
<div title="Enlarge" class="right_menu_button fa-lg fa-solid fa-magnifying-glass mes_img_enlarge" data-i18n="[title]Enlarge"></div>
|
<div title="Enlarge" class="right_menu_button fa-lg fa-solid fa-magnifying-glass mes_img_enlarge" data-i18n="[title]Enlarge"></div>
|
||||||
|
<div title="Caption" class="right_menu_button fa-lg fa-solid fa-envelope-open-text mes_img_caption" data-i18n="[title]Caption"></div>
|
||||||
<div title="Delete" class="right_menu_button fa-lg fa-solid fa-trash-can mes_img_delete" data-i18n="[title]Delete"></div>
|
<div title="Delete" class="right_menu_button fa-lg fa-solid fa-trash-can mes_img_delete" data-i18n="[title]Delete"></div>
|
||||||
</div>
|
</div>
|
||||||
<img class="mes_img" src="" />
|
<img class="mes_img" src="" />
|
||||||
|
|
|
@ -2079,14 +2079,23 @@ export function updateMessageBlock(messageId, message) {
|
||||||
appendMediaToMessage(message, messageElement);
|
appendMediaToMessage(message, messageElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function appendMediaToMessage(mes, messageElement) {
|
/**
|
||||||
|
* Appends image or file to the message element.
|
||||||
|
* @param {object} mes Message object
|
||||||
|
* @param {JQuery<HTMLElement>} 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
|
// Add image to message
|
||||||
if (mes.extra?.image) {
|
if (mes.extra?.image) {
|
||||||
const chatHeight = $('#chat').prop('scrollHeight');
|
const chatHeight = $('#chat').prop('scrollHeight');
|
||||||
const image = messageElement.find('.mes_img');
|
const image = messageElement.find('.mes_img');
|
||||||
const text = messageElement.find('.mes_text');
|
const text = messageElement.find('.mes_text');
|
||||||
const isInline = !!mes.extra?.inline_image;
|
const isInline = !!mes.extra?.inline_image;
|
||||||
image.on('load', function () {
|
image.off('load').on('load', function () {
|
||||||
|
if (!adjustScroll) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const scrollPosition = $('#chat').scrollTop();
|
const scrollPosition = $('#chat').scrollTop();
|
||||||
const newChatHeight = $('#chat').prop('scrollHeight');
|
const newChatHeight = $('#chat').prop('scrollHeight');
|
||||||
const diff = newChatHeight - chatHeight;
|
const diff = newChatHeight - chatHeight;
|
||||||
|
@ -5636,7 +5645,7 @@ export async function renameCharacter(name = null, { silent = false, renameChats
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (error) {
|
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');
|
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');
|
else toastr.error('Something went wrong. The page will be reloaded.', 'Rename Character');
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { ensureImageFormatSupported, getBase64Async, isTrueBoolean, saveBase64AsFile } from '../../utils.js';
|
import { ensureImageFormatSupported, getBase64Async, isTrueBoolean, saveBase64AsFile } from '../../utils.js';
|
||||||
import { getContext, getApiUrl, doExtrasFetch, extension_settings, modules, renderExtensionTemplateAsync } from '../../extensions.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 { getMessageTimeStamp } from '../../RossAscends-mods.js';
|
||||||
import { SECRET_KEYS, secret_state } from '../../secrets.js';
|
import { SECRET_KEYS, secret_state } from '../../secrets.js';
|
||||||
import { getMultimodalCaption } from '../shared.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_SENT, onMessageEvent);
|
||||||
eventSource.on(event_types.MESSAGE_FILE_EMBEDDED, 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',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'caption',
|
||||||
callback: captionCommandCallback,
|
callback: captionCommandCallback,
|
||||||
returns: 'caption',
|
returns: 'caption',
|
||||||
|
@ -548,4 +557,6 @@ jQuery(async function () {
|
||||||
</div>
|
</div>
|
||||||
`,
|
`,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
document.body.classList.add('caption');
|
||||||
});
|
});
|
||||||
|
|
|
@ -4481,7 +4481,8 @@ a {
|
||||||
}
|
}
|
||||||
|
|
||||||
.mes_img_controls .right_menu_button {
|
.mes_img_controls .right_menu_button {
|
||||||
filter: brightness(80%);
|
filter: brightness(90%);
|
||||||
|
text-shadow: 1px 1px var(--SmartThemeShadowColor) !important;
|
||||||
padding: 1px;
|
padding: 1px;
|
||||||
height: 1.25em;
|
height: 1.25em;
|
||||||
width: 1.25em;
|
width: 1.25em;
|
||||||
|
@ -4506,6 +4507,10 @@ a {
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body:not(.caption) .mes_img_caption {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.img_enlarged_holder {
|
.img_enlarged_holder {
|
||||||
/* Scaling via flex-grow and object-fit only works if we have some kind of base-height set */
|
/* Scaling via flex-grow and object-fit only works if we have some kind of base-height set */
|
||||||
min-height: 120px;
|
min-height: 120px;
|
||||||
|
|
Loading…
Reference in New Issue