Example messages behavior to 3-state selector

This commit is contained in:
Cohee 2023-10-20 20:09:31 +03:00
parent 0b0b125bca
commit e4cb916dff
2 changed files with 52 additions and 37 deletions

View File

@ -2521,18 +2521,6 @@
Always add character's name to prompt
</span>
</label>
<label data-newbie-hidden class="checkbox_label" for="pin-examples-checkbox">
<input id="pin-examples-checkbox" type="checkbox" />
<span data-i18n="Keep Example Messages in Prompt">
Keep Example Messages in Prompt
</span>
</label>
<label data-newbie-hidden class="checkbox_label" for="remove-examples-checkbox">
<input id="remove-examples-checkbox" type="checkbox" />
<span data-i18n="Strip Example Messages from Prompt">
Strip Example Messages from Prompt
</span>
</label>
<label class="checkbox_label" for="collapse-newlines-checkbox"><input id="collapse-newlines-checkbox" type="checkbox" />
<span data-i18n="Remove Empty New Lines from Output">
Remove Empty New Lines from Output
@ -3085,7 +3073,19 @@
<div name="UserSettingsThirdColumn" id="power-user-options-block" class="flex-container wide100p">
<div id="power-user-option-checkboxes">
<div data-newbie-hidden name="CharacterHandlingToggles">
<h4>Character Handling</h4>
<h4 data-i18n="Character Handling">
Character Handling
</h4>
<div data-newbie-hidden id="examples-behavior-block">
<label data-i18n="Example Messages Behavior">
Example Messages Behavior:
</label>
<select id="example_messages_behavior">
<option value="normal">Gradual push-out</option>
<option value="keep">Always include examples</option>
<option value="strip">Never include examples</option>
</select>
</div>
<label data-newbie-hidden class="checkbox_label" for="fuzzy_search_checkbox">
<input id="fuzzy_search_checkbox" type="checkbox" />
<span data-i18n="Advanced Character Search">Advanced Character Search</span>

View File

@ -836,6 +836,18 @@ switchMesIDDisplay();
switchTokenCount();
switchMessageActions();
function getExampleMessagesBehavior() {
if (power_user.strip_examples) {
return 'strip';
}
if (power_user.pin_examples) {
return 'keep';
}
return 'normal';
}
function loadPowerUserSettings(settings, data) {
// Load from settings.json
if (settings.power_user !== undefined) {
@ -911,6 +923,8 @@ function loadPowerUserSettings(settings, data) {
$('#fuzzy_search_checkbox').prop("checked", power_user.fuzzy_search);
$('#persona_show_notifications').prop("checked", power_user.persona_show_notifications);
$('#encode_tags').prop("checked", power_user.encode_tags);
$('#example_messages_behavior').val(getExampleMessagesBehavior());
$(`#example_messages_behavior option[value="${getExampleMessagesBehavior()}"]`).prop("selected", true);
$("#console_log_prompts").prop("checked", power_user.console_log_prompts);
$('#auto_fix_generated_markdown').prop("checked", power_user.auto_fix_generated_markdown);
@ -921,8 +935,6 @@ function loadPowerUserSettings(settings, data) {
$("#confirm_message_delete").prop("checked", power_user.confirm_message_delete !== undefined ? !!power_user.confirm_message_delete : true);
$("#spoiler_free_mode").prop("checked", power_user.spoiler_free_mode);
$("#collapse-newlines-checkbox").prop("checked", power_user.collapse_newlines);
$("#pin-examples-checkbox").prop("checked", power_user.pin_examples);
$("#remove-examples-checkbox").prop("checked", power_user.strip_examples);
$("#always-force-name2-checkbox").prop("checked", power_user.always_force_name2);
$("#trim_sentences_checkbox").prop("checked", power_user.trim_sentences);
$("#include_newline_checkbox").prop("checked", power_user.include_newline);
@ -1849,28 +1861,6 @@ $(document).ready(() => {
saveSettingsDebounced();
});
$("#pin-examples-checkbox").change(function () {
if ($(this).prop("checked")) {
$("#remove-examples-checkbox").prop("checked", false).prop("disabled", true);
power_user.strip_examples = false;
} else {
$("#remove-examples-checkbox").prop("disabled", false);
}
power_user.pin_examples = !!$(this).prop("checked");
saveSettingsDebounced();
});
$("#remove-examples-checkbox").change(function () {
if ($(this).prop("checked")) {
$("#pin-examples-checkbox").prop("checked", false).prop("disabled", true);
power_user.pin_examples = false;
} else {
$("#pin-examples-checkbox").prop("disabled", false);
}
power_user.strip_examples = !!$(this).prop("checked");
saveSettingsDebounced();
});
// include newline is the child of trim sentences
// if include newline is checked, trim sentences must be checked
// if trim sentences is unchecked, include newline must be unchecked
@ -1929,6 +1919,31 @@ $(document).ready(() => {
saveSettingsDebounced();
});
$('#example_messages_behavior').on('change', function () {
const selectedOption = String($(this).find(':selected').val());
console.log('Setting example messages behavior to', selectedOption);
switch (selectedOption) {
case 'normal':
power_user.pin_examples = false;
power_user.strip_examples = false;
break;
case 'keep':
power_user.pin_examples = true;
power_user.strip_examples = false;
break;
case 'strip':
power_user.pin_examples = false;
power_user.strip_examples = true;
break;
}
console.debug('power_user.pin_examples', power_user.pin_examples);
console.debug('power_user.strip_examples', power_user.strip_examples);
saveSettingsDebounced();
});
// Settings that go to local storage
$("#fast_ui_mode").change(function () {
power_user.fast_ui_mode = $(this).prop("checked");