mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge branch 'staging' into persona-improvements
This commit is contained in:
@@ -27,7 +27,6 @@ import {
|
||||
send_on_enter_options,
|
||||
} from './power-user.js';
|
||||
|
||||
import { LoadLocal, SaveLocal, LoadLocalBool } from './f-localStorage.js';
|
||||
import { selected_group, is_group_generating, openGroupById } from './group-chats.js';
|
||||
import { getTagKeyForEntity, applyTagsOnCharacterSelect } from './tags.js';
|
||||
import {
|
||||
@@ -41,6 +40,8 @@ import { textgen_types, textgenerationwebui_settings as textgen_settings, getTex
|
||||
import { debounce_timeout } from './constants.js';
|
||||
|
||||
import { Popup } from './popup.js';
|
||||
import { accountStorage } from './util/AccountStorage.js';
|
||||
import { getCurrentUserHandle } from './user.js';
|
||||
|
||||
var RPanelPin = document.getElementById('rm_button_panel_pin');
|
||||
var LPanelPin = document.getElementById('lm_button_panel_pin');
|
||||
@@ -279,17 +280,32 @@ async function RA_autoloadchat() {
|
||||
// active character is the name, we should look it up in the character list and get the id
|
||||
if (active_character !== null && active_character !== undefined) {
|
||||
const active_character_id = characters.findIndex(x => getTagKeyForEntity(x) === active_character);
|
||||
if (active_character_id !== null) {
|
||||
if (active_character_id !== -1) {
|
||||
await selectCharacterById(active_character_id);
|
||||
|
||||
// Do a little tomfoolery to spoof the tag selector
|
||||
const selectedCharElement = $(`#rm_print_characters_block .character_select[chid="${active_character_id}"]`);
|
||||
applyTagsOnCharacterSelect.call(selectedCharElement);
|
||||
} else {
|
||||
setActiveCharacter(null);
|
||||
saveSettingsDebounced();
|
||||
console.warn(`Currently active character with ID ${active_character} not found. Resetting to no active character.`);
|
||||
}
|
||||
}
|
||||
|
||||
if (active_group !== null && active_group !== undefined) {
|
||||
await openGroupById(String(active_group));
|
||||
if (active_character) {
|
||||
console.warn('Active character and active group are both set. Only active character will be loaded. Resetting active group.');
|
||||
setActiveGroup(null);
|
||||
saveSettingsDebounced();
|
||||
} else {
|
||||
const result = await openGroupById(String(active_group));
|
||||
if (!result) {
|
||||
setActiveGroup(null);
|
||||
saveSettingsDebounced();
|
||||
console.warn(`Currently active group with ID ${active_group} not found. Resetting to no active group.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if the character list hadn't been loaded yet, try again.
|
||||
@@ -409,32 +425,34 @@ function RA_autoconnect(PrevApi) {
|
||||
function OpenNavPanels() {
|
||||
if (!isMobile()) {
|
||||
//auto-open R nav if locked and previously open
|
||||
if (LoadLocalBool('NavLockOn') == true && LoadLocalBool('NavOpened') == true) {
|
||||
if (accountStorage.getItem('NavLockOn') == 'true' && accountStorage.getItem('NavOpened') == 'true') {
|
||||
//console.log("RA -- clicking right nav to open");
|
||||
$('#rightNavDrawerIcon').click();
|
||||
}
|
||||
|
||||
//auto-open L nav if locked and previously open
|
||||
if (LoadLocalBool('LNavLockOn') == true && LoadLocalBool('LNavOpened') == true) {
|
||||
if (accountStorage.getItem('LNavLockOn') == 'true' && accountStorage.getItem('LNavOpened') == 'true') {
|
||||
console.debug('RA -- clicking left nav to open');
|
||||
$('#leftNavDrawerIcon').click();
|
||||
}
|
||||
|
||||
//auto-open WI if locked and previously open
|
||||
if (LoadLocalBool('WINavLockOn') == true && LoadLocalBool('WINavOpened') == true) {
|
||||
if (accountStorage.getItem('WINavLockOn') == 'true' && accountStorage.getItem('WINavOpened') == 'true') {
|
||||
console.debug('RA -- clicking WI to open');
|
||||
$('#WIDrawerIcon').click();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const getUserInputKey = () => getCurrentUserHandle() + '_userInput';
|
||||
|
||||
function restoreUserInput() {
|
||||
if (!power_user.restore_user_input) {
|
||||
console.debug('restoreUserInput disabled');
|
||||
return;
|
||||
}
|
||||
|
||||
const userInput = LoadLocal('userInput');
|
||||
const userInput = localStorage.getItem(getUserInputKey());
|
||||
if (userInput) {
|
||||
$('#send_textarea').val(userInput)[0].dispatchEvent(new Event('input', { bubbles: true }));
|
||||
}
|
||||
@@ -442,7 +460,8 @@ function restoreUserInput() {
|
||||
|
||||
function saveUserInput() {
|
||||
const userInput = String($('#send_textarea').val());
|
||||
SaveLocal('userInput', userInput);
|
||||
localStorage.setItem(getUserInputKey(), userInput);
|
||||
console.debug('User Input -- ', userInput);
|
||||
}
|
||||
const saveUserInputDebounced = debounce(saveUserInput);
|
||||
|
||||
@@ -739,7 +758,7 @@ export function initRossMods() {
|
||||
|
||||
//toggle pin class when lock toggle clicked
|
||||
$(RPanelPin).on('click', function () {
|
||||
SaveLocal('NavLockOn', $(RPanelPin).prop('checked'));
|
||||
accountStorage.setItem('NavLockOn', $(RPanelPin).prop('checked'));
|
||||
if ($(RPanelPin).prop('checked') == true) {
|
||||
//console.log('adding pin class to right nav');
|
||||
$(RightNavPanel).addClass('pinnedOpen');
|
||||
@@ -757,7 +776,7 @@ export function initRossMods() {
|
||||
}
|
||||
});
|
||||
$(LPanelPin).on('click', function () {
|
||||
SaveLocal('LNavLockOn', $(LPanelPin).prop('checked'));
|
||||
accountStorage.setItem('LNavLockOn', $(LPanelPin).prop('checked'));
|
||||
if ($(LPanelPin).prop('checked') == true) {
|
||||
//console.log('adding pin class to Left nav');
|
||||
$(LeftNavPanel).addClass('pinnedOpen');
|
||||
@@ -776,7 +795,7 @@ export function initRossMods() {
|
||||
});
|
||||
|
||||
$(WIPanelPin).on('click', function () {
|
||||
SaveLocal('WINavLockOn', $(WIPanelPin).prop('checked'));
|
||||
accountStorage.setItem('WINavLockOn', $(WIPanelPin).prop('checked'));
|
||||
if ($(WIPanelPin).prop('checked') == true) {
|
||||
console.debug('adding pin class to WI');
|
||||
$(WorldInfo).addClass('pinnedOpen');
|
||||
@@ -796,8 +815,8 @@ export function initRossMods() {
|
||||
});
|
||||
|
||||
// read the state of right Nav Lock and apply to rightnav classlist
|
||||
$(RPanelPin).prop('checked', LoadLocalBool('NavLockOn'));
|
||||
if (LoadLocalBool('NavLockOn') == true) {
|
||||
$(RPanelPin).prop('checked', accountStorage.getItem('NavLockOn') == 'true');
|
||||
if (accountStorage.getItem('NavLockOn') == 'true') {
|
||||
//console.log('setting pin class via local var');
|
||||
$(RightNavPanel).addClass('pinnedOpen');
|
||||
$(RightNavDrawerIcon).addClass('drawerPinnedOpen');
|
||||
@@ -808,8 +827,8 @@ export function initRossMods() {
|
||||
$(RightNavDrawerIcon).addClass('drawerPinnedOpen');
|
||||
}
|
||||
// read the state of left Nav Lock and apply to leftnav classlist
|
||||
$(LPanelPin).prop('checked', LoadLocalBool('LNavLockOn'));
|
||||
if (LoadLocalBool('LNavLockOn') == true) {
|
||||
$(LPanelPin).prop('checked', accountStorage.getItem('LNavLockOn') === 'true');
|
||||
if (accountStorage.getItem('LNavLockOn') == 'true') {
|
||||
//console.log('setting pin class via local var');
|
||||
$(LeftNavPanel).addClass('pinnedOpen');
|
||||
$(LeftNavDrawerIcon).addClass('drawerPinnedOpen');
|
||||
@@ -821,8 +840,8 @@ export function initRossMods() {
|
||||
}
|
||||
|
||||
// read the state of left Nav Lock and apply to leftnav classlist
|
||||
$(WIPanelPin).prop('checked', LoadLocalBool('WINavLockOn'));
|
||||
if (LoadLocalBool('WINavLockOn') == true) {
|
||||
$(WIPanelPin).prop('checked', accountStorage.getItem('WINavLockOn') === 'true');
|
||||
if (accountStorage.getItem('WINavLockOn') == 'true') {
|
||||
//console.log('setting pin class via local var');
|
||||
$(WorldInfo).addClass('pinnedOpen');
|
||||
$(WIDrawerIcon).addClass('drawerPinnedOpen');
|
||||
@@ -837,22 +856,22 @@ export function initRossMods() {
|
||||
//save state of Right nav being open or closed
|
||||
$('#rightNavDrawerIcon').on('click', function () {
|
||||
if (!$('#rightNavDrawerIcon').hasClass('openIcon')) {
|
||||
SaveLocal('NavOpened', 'true');
|
||||
} else { SaveLocal('NavOpened', 'false'); }
|
||||
accountStorage.setItem('NavOpened', 'true');
|
||||
} else { accountStorage.setItem('NavOpened', 'false'); }
|
||||
});
|
||||
|
||||
//save state of Left nav being open or closed
|
||||
$('#leftNavDrawerIcon').on('click', function () {
|
||||
if (!$('#leftNavDrawerIcon').hasClass('openIcon')) {
|
||||
SaveLocal('LNavOpened', 'true');
|
||||
} else { SaveLocal('LNavOpened', 'false'); }
|
||||
accountStorage.setItem('LNavOpened', 'true');
|
||||
} else { accountStorage.setItem('LNavOpened', 'false'); }
|
||||
});
|
||||
|
||||
//save state of Left nav being open or closed
|
||||
$('#WorldInfo').on('click', function () {
|
||||
if (!$('#WorldInfo').hasClass('openIcon')) {
|
||||
SaveLocal('WINavOpened', 'true');
|
||||
} else { SaveLocal('WINavOpened', 'false'); }
|
||||
accountStorage.setItem('WINavOpened', 'true');
|
||||
} else { accountStorage.setItem('WINavOpened', 'false'); }
|
||||
});
|
||||
|
||||
var chatbarInFocus = false;
|
||||
@@ -868,8 +887,8 @@ export function initRossMods() {
|
||||
OpenNavPanels();
|
||||
}, 300);
|
||||
|
||||
$(SelectedCharacterTab).click(function () { SaveLocal('SelectedNavTab', 'rm_button_selected_ch'); });
|
||||
$('#rm_button_characters').click(function () { SaveLocal('SelectedNavTab', 'rm_button_characters'); });
|
||||
$(SelectedCharacterTab).click(function () { accountStorage.setItem('SelectedNavTab', 'rm_button_selected_ch'); });
|
||||
$('#rm_button_characters').click(function () { accountStorage.setItem('SelectedNavTab', 'rm_button_characters'); });
|
||||
|
||||
// when a char is selected from the list, save them as the auto-load character for next page load
|
||||
|
||||
@@ -1063,14 +1082,21 @@ export function initRossMods() {
|
||||
// Ctrl+Enter for Regeneration Last Response. If editing, accept the edits instead
|
||||
if (event.ctrlKey && event.key == 'Enter') {
|
||||
const editMesDone = $('.mes_edit_done:visible');
|
||||
const reasoningMesDone = $('.mes_reasoning_edit_done:visible');
|
||||
if (editMesDone.length > 0) {
|
||||
console.debug('Accepting edits with Ctrl+Enter');
|
||||
$('#send_textarea').focus();
|
||||
$('#send_textarea').trigger('focus');
|
||||
editMesDone.trigger('click');
|
||||
return;
|
||||
} else if (is_send_press == false) {
|
||||
} else if (reasoningMesDone.length > 0) {
|
||||
console.debug('Accepting edits with Ctrl+Enter');
|
||||
$('#send_textarea').trigger('focus');
|
||||
reasoningMesDone.trigger('click');
|
||||
return;
|
||||
}
|
||||
else if (is_send_press == false) {
|
||||
const skipConfirmKey = 'RegenerateWithCtrlEnter';
|
||||
const skipConfirm = LoadLocalBool(skipConfirmKey);
|
||||
const skipConfirm = accountStorage.getItem(skipConfirmKey) === 'true';
|
||||
function doRegenerate() {
|
||||
console.debug('Regenerating with Ctrl+Enter');
|
||||
$('#option_regenerate').trigger('click');
|
||||
@@ -1082,13 +1108,15 @@ export function initRossMods() {
|
||||
let regenerateWithCtrlEnter = false;
|
||||
const result = await Popup.show.confirm('Regenerate Message', 'Are you sure you want to regenerate the latest message?', {
|
||||
customInputs: [{ id: 'regenerateWithCtrlEnter', label: 'Don\'t ask again' }],
|
||||
onClose: (popup) => regenerateWithCtrlEnter = popup.inputResults.get('regenerateWithCtrlEnter') ?? false,
|
||||
onClose: (popup) => {
|
||||
regenerateWithCtrlEnter = popup.inputResults.get('regenerateWithCtrlEnter') ?? false;
|
||||
},
|
||||
});
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
|
||||
SaveLocal(skipConfirmKey, regenerateWithCtrlEnter);
|
||||
accountStorage.setItem(skipConfirmKey, String(regenerateWithCtrlEnter));
|
||||
doRegenerate();
|
||||
}
|
||||
return;
|
||||
|
Reference in New Issue
Block a user