diff --git a/public/index.html b/public/index.html index 3876f517c..d88998a1d 100644 --- a/public/index.html +++ b/public/index.html @@ -1216,6 +1216,15 @@ Disable chat start formatting + + +

Custom Chat Separator diff --git a/public/script.js b/public/script.js index 26b8f1c95..ae5215b27 100644 --- a/public/script.js +++ b/public/script.js @@ -106,7 +106,7 @@ import { setPoeOnlineStatus, } from "./scripts/poe.js"; -import { debounce, delay, restoreCaretPosition, saveCaretPosition } from "./scripts/utils.js"; +import { debounce, delay, restoreCaretPosition, saveCaretPosition, end_trim_to_sentence } from "./scripts/utils.js"; import { extension_settings, getContext, loadExtensionSettings } from "./scripts/extensions.js"; import { executeSlashCommands, getSlashCommandsHelp, registerSlashCommand } from "./scripts/slash-commands.js"; import { @@ -1662,6 +1662,10 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject, is_send_press = true; textareaText = $("#send_textarea").val(); $("#send_textarea").val('').trigger('input'); + + if (power_user.trim_sentences) { + textareaText = end_trim_to_sentence(textareaText, power_user.keep_newlines); + } } else { textareaText = ""; if (chat.length && chat[chat.length - 1]['is_user']) { diff --git a/public/scripts/power-user.js b/public/scripts/power-user.js index d27453f12..c0acbd1ad 100644 --- a/public/scripts/power-user.js +++ b/public/scripts/power-user.js @@ -76,6 +76,8 @@ let power_user = { disable_personality_formatting: false, disable_examples_formatting: false, disable_start_formatting: false, + trim_sentences: false, + keep_newlines: false, always_force_name2: false, multigen: false, multigen_first_chunk: 50, @@ -492,6 +494,8 @@ function loadPowerUserSettings(settings, data) { $("#always-force-name2-checkbox").prop("checked", power_user.always_force_name2); $("#disable-examples-formatting-checkbox").prop("checked", power_user.disable_examples_formatting); $('#disable-start-formatting-checkbox').prop("checked", power_user.disable_start_formatting); + $("#trim_sentences_checkbox").prop("checked", power_user.trim_sentences); + $("#keep_newlines_checkbox").prop("checked", power_user.keep_newlines); $('#render_formulas').prop("checked", power_user.render_formulas); $("#custom_chat_separator").val(power_user.custom_chat_separator); $("#fast_ui_mode").prop("checked", power_user.fast_ui_mode); @@ -856,6 +860,27 @@ $(document).ready(() => { saveSettingsDebounced(); }); + // keep newlines is the child of trim sentences + // if keep newlines is checked, trim sentences must be checked + // if trim sentences is unchecked, keep newlines must be unchecked + $("#trim_sentences_checkbox").change(function() { + power_user.trim_sentences = !!$(this).prop("checked"); + if (!$(this).prop("checked")) { + $("#keep_newlines_checkbox").prop("checked", false); + power_user.keep_newlines = false; + } + saveSettingsDebounced(); + }); + + $("#keep_newlines_checkbox").change(function() { + power_user.keep_newlines = !!$(this).prop("checked"); + if ($(this).prop("checked")) { + $("#trim_sentences_checkbox").prop("checked", true); + power_user.trim_sentences = true; + } + saveSettingsDebounced(); + }); + $("#always-force-name2-checkbox").change(function () { power_user.always_force_name2 = !!$(this).prop("checked"); saveSettingsDebounced(); diff --git a/public/scripts/utils.js b/public/scripts/utils.js index 6213f4506..116343dfa 100644 --- a/public/scripts/utils.js +++ b/public/scripts/utils.js @@ -188,4 +188,13 @@ export function sortByCssOrder(a, b) { const _a = Number($(a).css('order')); const _b = Number($(b).css('order')); return _a - _b; -} \ No newline at end of file +} + +export function end_trim_to_sentence(input, keep_newlines = false) { + if (!keep_newlines) { + return input.trimEnd(); + } else { + // trim all whitespace at the end of the string, except for newlines + return input.replace(/([^\S\r\n])+(?=\n*$)/g, ""); + } +}