diff --git a/public/index.html b/public/index.html index 611640279..79df2c168 100644 --- a/public/index.html +++ b/public/index.html @@ -1689,6 +1689,10 @@ Disable chat start formatting + + + Trim spaces + Trim Incomplete Sentences diff --git a/public/script.js b/public/script.js index 3e47b0880..cdf9f5569 100644 --- a/public/script.js +++ b/public/script.js @@ -3408,7 +3408,9 @@ function cleanUpMessage(getMessage, isImpersonate, displayIncompleteSentences = getMessage = collapseNewlines(getMessage); } - getMessage = $.trim(getMessage); + if (power_user.trim_spaces) { + getMessage = getMessage.trim(); + } // trailing invisible whitespace before every newlines, on a multiline string // "trailing whitespace on newlines \nevery line of the string \n?sample text" -> // "trailing whitespace on newlines\nevery line of the string\nsample text" @@ -3522,7 +3524,9 @@ function saveReply(type, getMessage, this_mes_is_name, title) { chat[chat.length - 1]['is_user'] = false; chat[chat.length - 1]['is_name'] = this_mes_is_name; chat[chat.length - 1]['send_date'] = getMessageTimeStamp(); - getMessage = $.trim(getMessage); + if (power_user.trim_spaces) { + getMessage = getMessage.trim(); + } chat[chat.length - 1]['mes'] = getMessage; chat[chat.length - 1]['title'] = title; chat[chat.length - 1]['gen_started'] = generation_started; @@ -4795,7 +4799,12 @@ function setCharacterBlockHeight() { // Common code for message editor done and auto-save function updateMessage(div) { const mesBlock = div.closest(".mes_block"); - const text = mesBlock.find(".edit_textarea").val().trim(); + let text = mesBlock.find(".edit_textarea").val(); + + if (power_user.trim_spaces) { + text = text.trim(); + } + const bias = extractMessageBias(text); const mes = chat[this_edit_mes_id]; mes["mes"] = text; @@ -7432,7 +7441,9 @@ $(document).ready(function () { } else { this_edit_mes_chname = name2; } - text = text.trim(); + if (power_user.trim_spaces) { + text = text.trim(); + } $(this) .closest(".mes_block") .find(".mes_text") @@ -7570,7 +7581,11 @@ $(document).ready(function () { let oldScroll = $('#chat')[0].scrollTop; const clone = JSON.parse(JSON.stringify(chat[this_edit_mes_id])); // quick and dirty clone clone.send_date = Date.now(); - clone.mes = $(this).closest(".mes").find('.edit_textarea').val().trim(); + clone.mes = $(this).closest(".mes").find('.edit_textarea').val(); + + if (power_user.trim_spaces) { + clone.mes = clone.mes.trim(); + } chat.splice(Number(this_edit_mes_id) + 1, 0, clone); addOneMessage(clone, { insertAfter: this_edit_mes_id }); diff --git a/public/scripts/power-user.js b/public/scripts/power-user.js index 4c0b04544..db59dfadf 100644 --- a/public/scripts/power-user.js +++ b/public/scripts/power-user.js @@ -163,6 +163,7 @@ let power_user = { prefer_character_prompt: true, prefer_character_jailbreak: true, continue_on_send: false, + trim_spaces: true, instruct: { enabled: false, @@ -609,6 +610,7 @@ function loadPowerUserSettings(settings, data) { power_user.font_scale = Number(localStorage.getItem(storage_keys.font_scale) ?? 1); power_user.blur_strength = Number(localStorage.getItem(storage_keys.blur_strength) ?? 10); + $('#trim_spaces').prop("checked", power_user.trim_spaces); $('#continue_on_send').prop("checked", power_user.continue_on_send); $('#auto_swipe').prop("checked", power_user.auto_swipe); $('#auto_swipe_minimum_length').val(power_user.auto_swipe_minimum_length); @@ -1515,6 +1517,12 @@ $(document).ready(() => { saveSettingsDebounced(); }); + $("#trim_spaces").on("input", function () { + const value = !!$(this).prop('checked'); + power_user.trim_spaces = value; + saveSettingsDebounced(); + }); + $(window).on('focus', function () { browser_has_focus = true; });