Alt+Click to open lorebook

a702dab68b4a23ad7acfa42394732cac1bb51764

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

3 files changed, +39 -10Showing whitespace changes
public/index.html+2 -2
@@ -4813,7 +4813,7 @@
4813 </div>4813 </div>
4814 <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">4814 <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">
4815 </div>4815 </div>
4816 <div id="persona_lore_button" class="menu_button fa-solid fa-globe" title="Persona Lore" data-i18n="[title]Persona Lore">4816 <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">
4817 </div>4817 </div>
4818 </div>4818 </div>
4819 <div>4819 <div>
@@ -4931,7 +4931,7 @@
4931 <input type="hidden" id="fav_checkbox" name="fav" />4931 <input type="hidden" id="fav_checkbox" name="fav" />
4932 <div id="advanced_div" class="menu_button fa-solid fa-book " title="Advanced Definitions" data-i18n="[title]Advanced Definition"></div>4932 <div id="advanced_div" class="menu_button fa-solid fa-book " title="Advanced Definitions" data-i18n="[title]Advanced Definition"></div>
4933 <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>4933 <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>
4934 <div class="chat_lorebook_button menu_button fa-solid fa-passport" title="Chat Lore" data-i18n="[title]Chat Lore"></div>4934 <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>
4935 <div id="export_button" class="menu_button fa-solid fa-file-export " title="Export and Download" data-i18n="[title]Export and Download"></div>4935 <div id="export_button" class="menu_button fa-solid fa-file-export " title="Export and Download" data-i18n="[title]Export and Download"></div>
4936 <!-- <div id="set_chat_scenario" class="menu_button fa-solid fa-scroll" title="Set a chat scenario override"></div> -->4936 <!-- <div id="set_chat_scenario" class="menu_button fa-solid fa-scroll" title="Set a chat scenario override"></div> -->
4937 <!-- <div id="set_character_world" class="menu_button fa-solid fa-globe" title="Set a character World Info / Lorebook"></div> -->4937 <!-- <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';
23import { selected_group } from './group-chats.js';23import { selected_group } from './group-chats.js';
24import { POPUP_RESULT, POPUP_TYPE, Popup, callGenericPopup } from './popup.js';24import { POPUP_RESULT, POPUP_TYPE, Popup, callGenericPopup } from './popup.js';
25import { t } from './i18n.js';25import { t } from './i18n.js';
26import { world_names } from './world-info.js';26import { openWorldInfoEditor, world_names } from './world-info.js';
27import { renderTemplateAsync } from './templates.js';27import { renderTemplateAsync } from './templates.js';
2828
29let savePersonasPage = 0;29let savePersonasPage = 0;
@@ -783,7 +783,11 @@ function onPersonaDescriptionDepthRoleInput() {
783 saveSettingsDebounced();783 saveSettingsDebounced();
784}784}
785785
786async function onPersonaLoreButtonClick() {786/**
787 * Opens a popup to set the lorebook for the current persona.
788 * @param {PointerEvent} event Click event
789 */
790async function onPersonaLoreButtonClick(event) {
787 const personaName = power_user.personas[user_avatar];791 const personaName = power_user.personas[user_avatar];
788 const selectedLorebook = power_user.persona_description_lorebook;792 const selectedLorebook = power_user.persona_description_lorebook;
789793
@@ -792,6 +796,11 @@ async function onPersonaLoreButtonClick() {
792 return;796 return;
793 }797 }
794798
799 if (event.altKey && selectedLorebook) {
800 openWorldInfoEditor(selectedLorebook);
801 return;
802 }
803
795 const template = $(await renderTemplateAsync('personaLorebook'));804 const template = $(await renderTemplateAsync('personaLorebook'));
796805
797 const worldSelect = template.find('select');806 const worldSelect = template.find('select');
public/scripts/world-info.js+26 -6
@@ -4855,8 +4855,32 @@ export async function importWorldInfo(file) {
4855 });4855 });
4856}4856}
48574857
4858export 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 */
4862export 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 */
4876export async function assignLorebookToChat(event) {
4859 const selectedName = chat_metadata[METADATA_KEY];4877 const selectedName = chat_metadata[METADATA_KEY];
4878
4879 if (selectedName && event.altKey) {
4880 openWorldInfoEditor(selectedName);
4881 return;
4882 }
4883
4860 const template = $(await renderTemplateAsync('chatLorebook'));4884 const template = $(await renderTemplateAsync('chatLorebook'));
48614885
4862 const worldSelect = template.find('select');4886 const worldSelect = template.find('select');
@@ -5036,11 +5060,7 @@ jQuery(() => {
5036 const worldName = characters[chid]?.data?.extensions?.world;5060 const worldName = characters[chid]?.data?.extensions?.world;
5037 const hasEmbed = checkEmbeddedWorld(chid);5061 const hasEmbed = checkEmbeddedWorld(chid);
5038 if (worldName && world_names.includes(worldName) && !event.shiftKey) {5062 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');
5044 } else if (hasEmbed && !event.shiftKey) {5064 } else if (hasEmbed && !event.shiftKey) {
5045 await importEmbeddedWorldInfo();5065 await importEmbeddedWorldInfo();
5046 saveCharacterDebounced();5066 saveCharacterDebounced();