mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Toggle for space trimming
This commit is contained in:
@ -1689,6 +1689,10 @@
|
|||||||
<input id="disable-start-formatting-checkbox" type="checkbox" />
|
<input id="disable-start-formatting-checkbox" type="checkbox" />
|
||||||
<span data-i18n="Disable chat start formatting">Disable chat start formatting</span>
|
<span data-i18n="Disable chat start formatting">Disable chat start formatting</span>
|
||||||
</label>
|
</label>
|
||||||
|
<label class="checkbox_label" for="trim_spaces">
|
||||||
|
<input id="trim_spaces" type="checkbox" />
|
||||||
|
<span data-i18n="Trim spaces">Trim spaces</span>
|
||||||
|
</label>
|
||||||
<label class="checkbox_label" for="trim_sentences_checkbox">
|
<label class="checkbox_label" for="trim_sentences_checkbox">
|
||||||
<input id="trim_sentences_checkbox" type="checkbox" />
|
<input id="trim_sentences_checkbox" type="checkbox" />
|
||||||
Trim Incomplete Sentences
|
Trim Incomplete Sentences
|
||||||
|
@ -3408,7 +3408,9 @@ function cleanUpMessage(getMessage, isImpersonate, displayIncompleteSentences =
|
|||||||
getMessage = collapseNewlines(getMessage);
|
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 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 \n?sample text" ->
|
||||||
// "trailing whitespace on newlines\nevery line of the string\nsample 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_user'] = false;
|
||||||
chat[chat.length - 1]['is_name'] = this_mes_is_name;
|
chat[chat.length - 1]['is_name'] = this_mes_is_name;
|
||||||
chat[chat.length - 1]['send_date'] = getMessageTimeStamp();
|
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]['mes'] = getMessage;
|
||||||
chat[chat.length - 1]['title'] = title;
|
chat[chat.length - 1]['title'] = title;
|
||||||
chat[chat.length - 1]['gen_started'] = generation_started;
|
chat[chat.length - 1]['gen_started'] = generation_started;
|
||||||
@ -4795,7 +4799,12 @@ function setCharacterBlockHeight() {
|
|||||||
// Common code for message editor done and auto-save
|
// Common code for message editor done and auto-save
|
||||||
function updateMessage(div) {
|
function updateMessage(div) {
|
||||||
const mesBlock = div.closest(".mes_block");
|
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 bias = extractMessageBias(text);
|
||||||
const mes = chat[this_edit_mes_id];
|
const mes = chat[this_edit_mes_id];
|
||||||
mes["mes"] = text;
|
mes["mes"] = text;
|
||||||
@ -7432,7 +7441,9 @@ $(document).ready(function () {
|
|||||||
} else {
|
} else {
|
||||||
this_edit_mes_chname = name2;
|
this_edit_mes_chname = name2;
|
||||||
}
|
}
|
||||||
text = text.trim();
|
if (power_user.trim_spaces) {
|
||||||
|
text = text.trim();
|
||||||
|
}
|
||||||
$(this)
|
$(this)
|
||||||
.closest(".mes_block")
|
.closest(".mes_block")
|
||||||
.find(".mes_text")
|
.find(".mes_text")
|
||||||
@ -7570,7 +7581,11 @@ $(document).ready(function () {
|
|||||||
let oldScroll = $('#chat')[0].scrollTop;
|
let oldScroll = $('#chat')[0].scrollTop;
|
||||||
const clone = JSON.parse(JSON.stringify(chat[this_edit_mes_id])); // quick and dirty clone
|
const clone = JSON.parse(JSON.stringify(chat[this_edit_mes_id])); // quick and dirty clone
|
||||||
clone.send_date = Date.now();
|
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);
|
chat.splice(Number(this_edit_mes_id) + 1, 0, clone);
|
||||||
addOneMessage(clone, { insertAfter: this_edit_mes_id });
|
addOneMessage(clone, { insertAfter: this_edit_mes_id });
|
||||||
|
@ -163,6 +163,7 @@ let power_user = {
|
|||||||
prefer_character_prompt: true,
|
prefer_character_prompt: true,
|
||||||
prefer_character_jailbreak: true,
|
prefer_character_jailbreak: true,
|
||||||
continue_on_send: false,
|
continue_on_send: false,
|
||||||
|
trim_spaces: true,
|
||||||
|
|
||||||
instruct: {
|
instruct: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
@ -609,6 +610,7 @@ function loadPowerUserSettings(settings, data) {
|
|||||||
power_user.font_scale = Number(localStorage.getItem(storage_keys.font_scale) ?? 1);
|
power_user.font_scale = Number(localStorage.getItem(storage_keys.font_scale) ?? 1);
|
||||||
power_user.blur_strength = Number(localStorage.getItem(storage_keys.blur_strength) ?? 10);
|
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);
|
$('#continue_on_send').prop("checked", power_user.continue_on_send);
|
||||||
$('#auto_swipe').prop("checked", power_user.auto_swipe);
|
$('#auto_swipe').prop("checked", power_user.auto_swipe);
|
||||||
$('#auto_swipe_minimum_length').val(power_user.auto_swipe_minimum_length);
|
$('#auto_swipe_minimum_length').val(power_user.auto_swipe_minimum_length);
|
||||||
@ -1515,6 +1517,12 @@ $(document).ready(() => {
|
|||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#trim_spaces").on("input", function () {
|
||||||
|
const value = !!$(this).prop('checked');
|
||||||
|
power_user.trim_spaces = value;
|
||||||
|
saveSettingsDebounced();
|
||||||
|
});
|
||||||
|
|
||||||
$(window).on('focus', function () {
|
$(window).on('focus', function () {
|
||||||
browser_has_focus = true;
|
browser_has_focus = true;
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user