Update persona name if it is bound by user name input
This commit is contained in:
parent
f3099ac270
commit
ee75adbd2d
|
@ -184,7 +184,7 @@ import {
|
|||
} from './scripts/instruct-mode.js';
|
||||
import { applyLocale, initLocales } from './scripts/i18n.js';
|
||||
import { getFriendlyTokenizerName, getTokenCount, getTokenizerModel, initTokenizers, saveTokenCache } from './scripts/tokenizers.js';
|
||||
import { createPersona, initPersonas, selectCurrentPersona, setPersonaDescription } from './scripts/personas.js';
|
||||
import { createPersona, initPersonas, selectCurrentPersona, setPersonaDescription, updatePersonaNameIfExists } from './scripts/personas.js';
|
||||
import { getBackgrounds, initBackgrounds, loadBackgroundSettings, background_settings } from './scripts/backgrounds.js';
|
||||
import { hideLoader, showLoader } from './scripts/loader.js';
|
||||
import { BulkEditOverlay, CharacterContextMenu } from './scripts/BulkEditOverlay.js';
|
||||
|
@ -9159,8 +9159,10 @@ jQuery(async function () {
|
|||
await messageEditDone($(this));
|
||||
});
|
||||
|
||||
$('#your_name_button').click(function () {
|
||||
setUserName($('#your_name').val());
|
||||
$('#your_name_button').click(async function () {
|
||||
const userName = String($('#your_name').val()).trim();
|
||||
setUserName(userName);
|
||||
await updatePersonaNameIfExists(user_avatar, userName);
|
||||
});
|
||||
|
||||
$('#sync_name_button').on('click', async function () {
|
||||
|
|
|
@ -193,6 +193,22 @@ export function autoSelectPersona(name) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the name of a persona if it exists.
|
||||
* @param {string} avatarId User avatar id
|
||||
* @param {string} newName New name for the persona
|
||||
*/
|
||||
export async function updatePersonaNameIfExists(avatarId, newName) {
|
||||
if (avatarId in power_user.personas) {
|
||||
power_user.personas[avatarId] = newName;
|
||||
await getUserAvatars();
|
||||
saveSettingsDebounced();
|
||||
console.log(`Updated persona name for ${avatarId} to ${newName}`);
|
||||
} else {
|
||||
console.log(`Persona name ${avatarId} was not updated because it does not exist`);
|
||||
}
|
||||
}
|
||||
|
||||
async function bindUserNameToPersona() {
|
||||
const avatarId = $(this).closest('.avatar-container').find('.avatar').attr('imgfile');
|
||||
|
||||
|
|
Loading…
Reference in New Issue