mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
add trim sentence feature
This commit is contained in:
@ -1216,6 +1216,15 @@
|
|||||||
<input id="disable-start-formatting-checkbox" type="checkbox" />
|
<input id="disable-start-formatting-checkbox" type="checkbox" />
|
||||||
Disable chat start formatting
|
Disable chat start formatting
|
||||||
</label>
|
</label>
|
||||||
|
<label class="checkbox_label" for="trim_sentences_checkbox">
|
||||||
|
<input id="trim_sentences_checkbox" type="checkbox" />
|
||||||
|
Trim Sentences
|
||||||
|
</label>
|
||||||
|
<!-- Add margin since this is a child of above -->
|
||||||
|
<label style="margin-left: 1em;" class="checkbox_label" for="keep_newlines_checkbox">
|
||||||
|
<input id="keep_newlines_checkbox" type="checkbox" />
|
||||||
|
Keep Newlines
|
||||||
|
</label>
|
||||||
<div>
|
<div>
|
||||||
<h4>
|
<h4>
|
||||||
Custom Chat Separator
|
Custom Chat Separator
|
||||||
|
@ -106,7 +106,7 @@ import {
|
|||||||
setPoeOnlineStatus,
|
setPoeOnlineStatus,
|
||||||
} from "./scripts/poe.js";
|
} 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 { extension_settings, getContext, loadExtensionSettings } from "./scripts/extensions.js";
|
||||||
import { executeSlashCommands, getSlashCommandsHelp, registerSlashCommand } from "./scripts/slash-commands.js";
|
import { executeSlashCommands, getSlashCommandsHelp, registerSlashCommand } from "./scripts/slash-commands.js";
|
||||||
import {
|
import {
|
||||||
@ -1662,6 +1662,10 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
is_send_press = true;
|
is_send_press = true;
|
||||||
textareaText = $("#send_textarea").val();
|
textareaText = $("#send_textarea").val();
|
||||||
$("#send_textarea").val('').trigger('input');
|
$("#send_textarea").val('').trigger('input');
|
||||||
|
|
||||||
|
if (power_user.trim_sentences) {
|
||||||
|
textareaText = end_trim_to_sentence(textareaText, power_user.keep_newlines);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
textareaText = "";
|
textareaText = "";
|
||||||
if (chat.length && chat[chat.length - 1]['is_user']) {
|
if (chat.length && chat[chat.length - 1]['is_user']) {
|
||||||
|
@ -76,6 +76,8 @@ let power_user = {
|
|||||||
disable_personality_formatting: false,
|
disable_personality_formatting: false,
|
||||||
disable_examples_formatting: false,
|
disable_examples_formatting: false,
|
||||||
disable_start_formatting: false,
|
disable_start_formatting: false,
|
||||||
|
trim_sentences: false,
|
||||||
|
keep_newlines: false,
|
||||||
always_force_name2: false,
|
always_force_name2: false,
|
||||||
multigen: false,
|
multigen: false,
|
||||||
multigen_first_chunk: 50,
|
multigen_first_chunk: 50,
|
||||||
@ -492,6 +494,8 @@ function loadPowerUserSettings(settings, data) {
|
|||||||
$("#always-force-name2-checkbox").prop("checked", power_user.always_force_name2);
|
$("#always-force-name2-checkbox").prop("checked", power_user.always_force_name2);
|
||||||
$("#disable-examples-formatting-checkbox").prop("checked", power_user.disable_examples_formatting);
|
$("#disable-examples-formatting-checkbox").prop("checked", power_user.disable_examples_formatting);
|
||||||
$('#disable-start-formatting-checkbox').prop("checked", power_user.disable_start_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);
|
$('#render_formulas').prop("checked", power_user.render_formulas);
|
||||||
$("#custom_chat_separator").val(power_user.custom_chat_separator);
|
$("#custom_chat_separator").val(power_user.custom_chat_separator);
|
||||||
$("#fast_ui_mode").prop("checked", power_user.fast_ui_mode);
|
$("#fast_ui_mode").prop("checked", power_user.fast_ui_mode);
|
||||||
@ -856,6 +860,27 @@ $(document).ready(() => {
|
|||||||
saveSettingsDebounced();
|
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 () {
|
$("#always-force-name2-checkbox").change(function () {
|
||||||
power_user.always_force_name2 = !!$(this).prop("checked");
|
power_user.always_force_name2 = !!$(this).prop("checked");
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
|
@ -189,3 +189,12 @@ export function sortByCssOrder(a, b) {
|
|||||||
const _b = Number($(b).css('order'));
|
const _b = Number($(b).css('order'));
|
||||||
return _a - _b;
|
return _a - _b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user