From e4cb916dffa39894ec23615d43f130172abcd603 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 20 Oct 2023 20:09:31 +0300 Subject: [PATCH] Example messages behavior to 3-state selector --- public/index.html | 26 +++++++-------- public/scripts/power-user.js | 63 ++++++++++++++++++++++-------------- 2 files changed, 52 insertions(+), 37 deletions(-) diff --git a/public/index.html b/public/index.html index 8391aceac..fc78bd035 100644 --- a/public/index.html +++ b/public/index.html @@ -2521,18 +2521,6 @@ Always add character's name to prompt - - - - Keep Example Messages in Prompt - - - - - - Strip Example Messages from Prompt - - Remove Empty New Lines from Output @@ -3085,7 +3073,19 @@ - Character Handling + + Character Handling + + + + Example Messages Behavior: + + + Gradual push-out + Always include examples + Never include examples + + Advanced Character Search diff --git a/public/scripts/power-user.js b/public/scripts/power-user.js index 045c9960e..6345904ff 100644 --- a/public/scripts/power-user.js +++ b/public/scripts/power-user.js @@ -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");