Alt+Click to open lorebook

This commit is contained in:
Cohee 2024-12-04 13:53:10 +00:00
parent efe25ddc04
commit a702dab68b
3 changed files with 39 additions and 10 deletions

View File

@ -4813,7 +4813,7 @@
</div> </div>
<div id="sync_name_button" class="menu_button fa-solid fa-sync" title="Click to set user name for all messages" data-i18n="[title]Click to set user name for all messages"> <div id="sync_name_button" class="menu_button fa-solid fa-sync" title="Click to set user name for all messages" data-i18n="[title]Click to set user name for all messages">
</div> </div>
<div id="persona_lore_button" class="menu_button fa-solid fa-globe" title="Persona Lore" data-i18n="[title]Persona Lore"> <div id="persona_lore_button" class="menu_button fa-solid fa-globe" title="Persona Lore&#10;Alt+Click to open the lorebook" data-i18n="[title]Persona Lore Alt+Click to open the lorebook">
</div> </div>
</div> </div>
<div> <div>
@ -4931,7 +4931,7 @@
<input type="hidden" id="fav_checkbox" name="fav" /> <input type="hidden" id="fav_checkbox" name="fav" />
<div id="advanced_div" class="menu_button fa-solid fa-book " title="Advanced Definitions" data-i18n="[title]Advanced Definition"></div> <div id="advanced_div" class="menu_button fa-solid fa-book " title="Advanced Definitions" data-i18n="[title]Advanced Definition"></div>
<div id="world_button" class="menu_button fa-solid fa-globe" title="Character Lore&#10;&#10;Click to load&#10;Shift-click to open 'Link to World Info' popup" data-i18n="[title]world_button_title"></div> <div id="world_button" class="menu_button fa-solid fa-globe" title="Character Lore&#10;&#10;Click to load&#10;Shift-click to open 'Link to World Info' popup" data-i18n="[title]world_button_title"></div>
<div class="chat_lorebook_button menu_button fa-solid fa-passport" title="Chat Lore" data-i18n="[title]Chat Lore"></div> <div class="chat_lorebook_button menu_button fa-solid fa-passport" title="Chat Lore&#10;Alt+Click to open the lorebook" data-i18n="[title]Chat Lore Alt+Click to open the lorebook"></div>
<div id="export_button" class="menu_button fa-solid fa-file-export " title="Export and Download" data-i18n="[title]Export and Download"></div> <div id="export_button" class="menu_button fa-solid fa-file-export " title="Export and Download" data-i18n="[title]Export and Download"></div>
<!-- <div id="set_chat_scenario" class="menu_button fa-solid fa-scroll" title="Set a chat scenario override"></div> --> <!-- <div id="set_chat_scenario" class="menu_button fa-solid fa-scroll" title="Set a chat scenario override"></div> -->
<!-- <div id="set_character_world" class="menu_button fa-solid fa-globe" title="Set a character World Info / Lorebook"></div> --> <!-- <div id="set_character_world" class="menu_button fa-solid fa-globe" title="Set a character World Info / Lorebook"></div> -->

View File

@ -23,7 +23,7 @@ import { FILTER_TYPES, FilterHelper } from './filters.js';
import { selected_group } from './group-chats.js'; import { selected_group } from './group-chats.js';
import { POPUP_RESULT, POPUP_TYPE, Popup, callGenericPopup } from './popup.js'; import { POPUP_RESULT, POPUP_TYPE, Popup, callGenericPopup } from './popup.js';
import { t } from './i18n.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'; import { renderTemplateAsync } from './templates.js';
let savePersonasPage = 0; let savePersonasPage = 0;
@ -783,7 +783,11 @@ function onPersonaDescriptionDepthRoleInput() {
saveSettingsDebounced(); 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 personaName = power_user.personas[user_avatar];
const selectedLorebook = power_user.persona_description_lorebook; const selectedLorebook = power_user.persona_description_lorebook;
@ -792,6 +796,11 @@ async function onPersonaLoreButtonClick() {
return; return;
} }
if (event.altKey && selectedLorebook) {
openWorldInfoEditor(selectedLorebook);
return;
}
const template = $(await renderTemplateAsync('personaLorebook')); const template = $(await renderTemplateAsync('personaLorebook'));
const worldSelect = template.find('select'); const worldSelect = template.find('select');

View File

@ -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<void>}
*/
export async function assignLorebookToChat(event) {
const selectedName = chat_metadata[METADATA_KEY]; const selectedName = chat_metadata[METADATA_KEY];
if (selectedName && event.altKey) {
openWorldInfoEditor(selectedName);
return;
}
const template = $(await renderTemplateAsync('chatLorebook')); const template = $(await renderTemplateAsync('chatLorebook'));
const worldSelect = template.find('select'); const worldSelect = template.find('select');
@ -5036,11 +5060,7 @@ jQuery(() => {
const worldName = characters[chid]?.data?.extensions?.world; const worldName = characters[chid]?.data?.extensions?.world;
const hasEmbed = checkEmbeddedWorld(chid); const hasEmbed = checkEmbeddedWorld(chid);
if (worldName && world_names.includes(worldName) && !event.shiftKey) { if (worldName && world_names.includes(worldName) && !event.shiftKey) {
if (!$('#WorldInfo').is(':visible')) { openWorldInfoEditor(worldName);
$('#WIDrawerIcon').trigger('click');
}
const index = world_names.indexOf(worldName);
$('#world_editor_select').val(index).trigger('change');
} else if (hasEmbed && !event.shiftKey) { } else if (hasEmbed && !event.shiftKey) {
await importEmbeddedWorldInfo(); await importEmbeddedWorldInfo();
saveCharacterDebounced(); saveCharacterDebounced();