diff --git a/public/index.html b/public/index.html index 986c95638..648286958 100644 --- a/public/index.html +++ b/public/index.html @@ -4813,7 +4813,7 @@ -
@@ -4931,7 +4931,7 @@ - + diff --git a/public/scripts/personas.js b/public/scripts/personas.js index 57f6026c7..930e87a4e 100644 --- a/public/scripts/personas.js +++ b/public/scripts/personas.js @@ -23,7 +23,7 @@ import { FILTER_TYPES, FilterHelper } from './filters.js'; import { selected_group } from './group-chats.js'; import { POPUP_RESULT, POPUP_TYPE, Popup, callGenericPopup } from './popup.js'; import { t } from './i18n.js'; -import { world_names } from './world-info.js'; +import { openWorldInfoEditor, world_names } from './world-info.js'; import { renderTemplateAsync } from './templates.js'; let savePersonasPage = 0; @@ -783,7 +783,11 @@ function onPersonaDescriptionDepthRoleInput() { saveSettingsDebounced(); } -async function onPersonaLoreButtonClick() { +/** + * Opens a popup to set the lorebook for the current persona. + * @param {PointerEvent} event Click event + */ +async function onPersonaLoreButtonClick(event) { const personaName = power_user.personas[user_avatar]; const selectedLorebook = power_user.persona_description_lorebook; @@ -792,6 +796,11 @@ async function onPersonaLoreButtonClick() { return; } + if (event.altKey && selectedLorebook) { + openWorldInfoEditor(selectedLorebook); + return; + } + const template = $(await renderTemplateAsync('personaLorebook')); const worldSelect = template.find('select'); diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index d1265ba7c..51426a260 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -4855,8 +4855,32 @@ export async function importWorldInfo(file) { }); } -export async function assignLorebookToChat() { +/** + * Forces the world info editor to open on a specific world. + * @param {string} worldName The name of the world to open + */ +export function openWorldInfoEditor(worldName) { + console.log(`Opening lorebook for ${worldName}`); + if (!$('#WorldInfo').is(':visible')) { + $('#WIDrawerIcon').trigger('click'); + } + const index = world_names.indexOf(worldName); + $('#world_editor_select').val(index).trigger('change'); +} + +/** + * Assigns a lorebook to the current chat. + * @param {PointerEvent} event Pointer event + * @returns {Promise} + */ +export async function assignLorebookToChat(event) { const selectedName = chat_metadata[METADATA_KEY]; + + if (selectedName && event.altKey) { + openWorldInfoEditor(selectedName); + return; + } + const template = $(await renderTemplateAsync('chatLorebook')); const worldSelect = template.find('select'); @@ -5036,11 +5060,7 @@ jQuery(() => { const worldName = characters[chid]?.data?.extensions?.world; const hasEmbed = checkEmbeddedWorld(chid); if (worldName && world_names.includes(worldName) && !event.shiftKey) { - if (!$('#WorldInfo').is(':visible')) { - $('#WIDrawerIcon').trigger('click'); - } - const index = world_names.indexOf(worldName); - $('#world_editor_select').val(index).trigger('change'); + openWorldInfoEditor(worldName); } else if (hasEmbed && !event.shiftKey) { await importEmbeddedWorldInfo(); saveCharacterDebounced();