Return to using string type for this_chid

This commit is contained in:
Cohee 2025-02-28 13:37:36 +00:00
parent b6af55134a
commit b2ce76c84c

View File

@ -1378,7 +1378,7 @@ export async function selectCharacterById(id) {
return; return;
} }
if (selected_group || this_chid !== id) { if (selected_group || String(this_chid) !== String(id)) {
//if clicked on a different character from what was currently selected //if clicked on a different character from what was currently selected
if (!is_send_press) { if (!is_send_press) {
await clearChat(); await clearChat();
@ -1386,7 +1386,7 @@ export async function selectCharacterById(id) {
resetSelectedGroup(); resetSelectedGroup();
this_edit_mes_id = undefined; this_edit_mes_id = undefined;
selected_button = 'character_edit'; selected_button = 'character_edit';
this_chid = id; setCharacterId(id);
chat.length = 0; chat.length = 0;
chat_metadata = {}; chat_metadata = {};
await getChat(); await getChat();
@ -6233,8 +6233,25 @@ export function setExternalAbortController(controller) {
abortController = controller; abortController = controller;
} }
/**
* Sets a character array index.
* @param {number|string|undefined} value
*/
export function setCharacterId(value) { export function setCharacterId(value) {
this_chid = value; switch (typeof value) {
case 'number':
this_chid = String(value);
break;
case 'string':
this_chid = !isNaN(parseInt(value)) ? value : undefined;
break;
case 'undefined':
this_chid = undefined;
break;
default:
console.error('Invalid character ID type:', value);
break;
}
} }
export function setCharacterName(value) { export function setCharacterName(value) {
@ -6350,13 +6367,13 @@ export async function renameCharacter(name = null, { silent = false, renameChats
if (newChId !== -1) { if (newChId !== -1) {
// Select the character after the renaming // Select the character after the renaming
this_chid = -1; setCharacterId(undefined);
await selectCharacterById(newChId); await selectCharacterById(newChId);
// Async delay to update UI // Async delay to update UI
await delay(1); await delay(1);
if (this_chid === -1) { if (this_chid === undefined) {
throw new Error('New character not selected'); throw new Error('New character not selected');
} }
@ -7658,7 +7675,7 @@ export function select_rm_info(type, charId, previousCharId = null) {
if (previousCharId) { if (previousCharId) {
const newId = characters.findIndex((x) => x.avatar == previousCharId); const newId = characters.findIndex((x) => x.avatar == previousCharId);
if (newId >= 0) { if (newId >= 0) {
this_chid = newId; setCharacterId(newId);
} }
} }
} }