Alt+Click to open lorebook

a702dab68b4a23ad7acfa42394732cac1bb51764

Cohee <18619528+Cohee1207@users.noreply.github.com>

3 files changed, +39 -10Ignore whitespace
public/index.html+2 -2
@@ -4813,7 +4813,7 @@
48134813 </div>
48144814 <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">
48154815 </div>
48164816 <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">
48174817 </div>
48184818 </div>
48194819 <div>
@@ -4931,7 +4931,7 @@
49314931 <input type="hidden" id="fav_checkbox" name="fav" />
49324932 <div id="advanced_div" class="menu_button fa-solid fa-book " title="Advanced Definitions" data-i18n="[title]Advanced Definition"></div>
49334933 <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>
49344934 <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>
49354935 <div id="export_button" class="menu_button fa-solid fa-file-export " title="Export and Download" data-i18n="[title]Export and Download"></div>
49364936 <!-- <div id="set_chat_scenario" class="menu_button fa-solid fa-scroll" title="Set a chat scenario override"></div> -->
49374937 <!-- <div id="set_character_world" class="menu_button fa-solid fa-globe" title="Set a character World Info / Lorebook"></div> -->
public/scripts/personas.js+11 -2
@@ -23,7 +23,7 @@ import { FILTER_TYPES, FilterHelper } from './filters.js';
2323import { selected_group } from './group-chats.js';
2424import { POPUP_RESULT, POPUP_TYPE, Popup, callGenericPopup } from './popup.js';
2525import { t } from './i18n.js';
2626import { openWorldInfoEditor, world_names } from './world-info.js';
2727import { renderTemplateAsync } from './templates.js';
2828
2929let savePersonasPage = 0;
@@ -783,7 +783,11 @@ function onPersonaDescriptionDepthRoleInput() {
783783 saveSettingsDebounced();
784784}
785785
786-async function onPersonaLoreButtonClick() {
786+/**
787+ * Opens a popup to set the lorebook for the current persona.
788+ * @param {PointerEvent} event Click event
789+ */
790+async function onPersonaLoreButtonClick(event) {
787791 const personaName = power_user.personas[user_avatar];
788792 const selectedLorebook = power_user.persona_description_lorebook;
789793
@@ -792,6 +796,11 @@ async function onPersonaLoreButtonClick() {
792796 return;
793797 }
794798
799+ if (event.altKey && selectedLorebook) {
800+ openWorldInfoEditor(selectedLorebook);
801+ return;
802+ }
803+
795804 const template = $(await renderTemplateAsync('personaLorebook'));
796805
797806 const worldSelect = template.find('select');
public/scripts/world-info.js+26 -6
@@ -4855,8 +4855,32 @@ export async function importWorldInfo(file) {
48554855 });
48564856}
48574857
4858-export async function assignLorebookToChat() {
4858+/**
4859+ * Forces the world info editor to open on a specific world.
4860+ * @param {string} worldName The name of the world to open
4861+ */
4862+export function openWorldInfoEditor(worldName) {
4863+ console.log(`Opening lorebook for ${worldName}`);
4864+ if (!$('#WorldInfo').is(':visible')) {
4865+ $('#WIDrawerIcon').trigger('click');
4866+ }
4867+ const index = world_names.indexOf(worldName);
4868+ $('#world_editor_select').val(index).trigger('change');
4869+}
4870+
4871+/**
4872+ * Assigns a lorebook to the current chat.
4873+ * @param {PointerEvent} event Pointer event
4874+ * @returns {Promise<void>}
4875+ */
4876+export async function assignLorebookToChat(event) {
48594877 const selectedName = chat_metadata[METADATA_KEY];
4878+
4879+ if (selectedName && event.altKey) {
4880+ openWorldInfoEditor(selectedName);
4881+ return;
4882+ }
4883+
48604884 const template = $(await renderTemplateAsync('chatLorebook'));
48614885
48624886 const worldSelect = template.find('select');
@@ -5036,11 +5060,7 @@ jQuery(() => {
50365060 const worldName = characters[chid]?.data?.extensions?.world;
50375061 const hasEmbed = checkEmbeddedWorld(chid);
50385062 if (worldName && world_names.includes(worldName) && !event.shiftKey) {
5039- if (!$('#WorldInfo').is(':visible')) {
5063+ openWorldInfoEditor(worldName);
5040- $('#WIDrawerIcon').trigger('click');
5041- }
5042- const index = world_names.indexOf(worldName);
5043- $('#world_editor_select').val(index).trigger('change');
50445064 } else if (hasEmbed && !event.shiftKey) {
50455065 await importEmbeddedWorldInfo();
50465066 saveCharacterDebounced();