Return to using string type for this_chid

b2ce76c84c480b318426b45f6673759e63784a25

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

1 files changed, +23 -6Ignore whitespace
public/script.js+23 -6
@@ -1378,7 +1378,7 @@ export async function selectCharacterById(id) {
1378 return;1378 return;
1379 }1379 }
13801380
1381 if (selected_group || this_chid !== id) {1381 if (selected_group || String(this_chid) !== String(id)) {
1382 //if clicked on a different character from what was currently selected1382 //if clicked on a different character from what was currently selected
1383 if (!is_send_press) {1383 if (!is_send_press) {
1384 await clearChat();1384 await clearChat();
@@ -1386,7 +1386,7 @@ export async function selectCharacterById(id) {
1386 resetSelectedGroup();1386 resetSelectedGroup();
1387 this_edit_mes_id = undefined;1387 this_edit_mes_id = undefined;
1388 selected_button = 'character_edit';1388 selected_button = 'character_edit';
1389 this_chid = id;1389 setCharacterId(id);
1390 chat.length = 0;1390 chat.length = 0;
1391 chat_metadata = {};1391 chat_metadata = {};
1392 await getChat();1392 await getChat();
@@ -6233,8 +6233,25 @@ export function setExternalAbortController(controller) {
6233 abortController = controller;6233 abortController = controller;
6234}6234}
62356235
6236/**
6237 * Sets a character array index.
6238 * @param {number|string|undefined} value
6239 */
6236export function setCharacterId(value) {6240export function setCharacterId(value) {
6237 this_chid = value;6241 switch (typeof value) {
6242 case 'number':
6243 this_chid = String(value);
6244 break;
6245 case 'string':
6246 this_chid = !isNaN(parseInt(value)) ? value : undefined;
6247 break;
6248 case 'undefined':
6249 this_chid = undefined;
6250 break;
6251 default:
6252 console.error('Invalid character ID type:', value);
6253 break;
6254 }
6238}6255}
62396256
6240export function setCharacterName(value) {6257export function setCharacterName(value) {
@@ -6350,13 +6367,13 @@ export async function renameCharacter(name = null, { silent = false, renameChats
63506367
6351 if (newChId !== -1) {6368 if (newChId !== -1) {
6352 // Select the character after the renaming6369 // Select the character after the renaming
6353 this_chid = -1;6370 setCharacterId(undefined);
6354 await selectCharacterById(newChId);6371 await selectCharacterById(newChId);
63556372
6356 // Async delay to update UI6373 // Async delay to update UI
6357 await delay(1);6374 await delay(1);
63586375
6359 if (this_chid === -1) {6376 if (this_chid === undefined) {
6360 throw new Error('New character not selected');6377 throw new Error('New character not selected');
6361 }6378 }
63626379
@@ -7658,7 +7675,7 @@ export function select_rm_info(type, charId, previousCharId = null) {
7658 if (previousCharId) {7675 if (previousCharId) {
7659 const newId = characters.findIndex((x) => x.avatar == previousCharId);7676 const newId = characters.findIndex((x) => x.avatar == previousCharId);
7660 if (newId >= 0) {7677 if (newId >= 0) {
7661 this_chid = newId;7678 setCharacterId(newId);
7662 }7679 }
7663 }7680 }
7664}7681}