change keep newline to include newline

This commit is contained in:
Sanskar Tiwari
2023-05-15 21:00:24 +05:30
parent ab124cb926
commit c8b77c0d58
4 changed files with 17 additions and 17 deletions

View File

@ -1221,9 +1221,9 @@
Trim Sentences Trim Sentences
</label> </label>
<!-- Add margin since this is a child of above --> <!-- Add margin since this is a child of above -->
<label style="margin-left: 1em;" class="checkbox_label" for="keep_newlines_checkbox"> <label style="margin-left: 1em;" class="checkbox_label" for="include_newline_checkbox">
<input id="keep_newlines_checkbox" type="checkbox" /> <input id="include_newline_checkbox" type="checkbox" />
Keep Newlines Include Newline
</label> </label>
<div> <div>
<h4> <h4>

View File

@ -1664,7 +1664,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
$("#send_textarea").val('').trigger('input'); $("#send_textarea").val('').trigger('input');
if (power_user.trim_sentences) { if (power_user.trim_sentences) {
textareaText = end_trim_to_sentence(textareaText, power_user.keep_newlines); textareaText = end_trim_to_sentence(textareaText, power_user.include_newline);
} }
} else { } else {
textareaText = ""; textareaText = "";

View File

@ -77,7 +77,7 @@ let power_user = {
disable_examples_formatting: false, disable_examples_formatting: false,
disable_start_formatting: false, disable_start_formatting: false,
trim_sentences: false, trim_sentences: false,
keep_newlines: false, include_newline: false,
always_force_name2: false, always_force_name2: false,
multigen: false, multigen: false,
multigen_first_chunk: 50, multigen_first_chunk: 50,
@ -495,7 +495,7 @@ function loadPowerUserSettings(settings, data) {
$("#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); $("#trim_sentences_checkbox").prop("checked", power_user.trim_sentences);
$("#keep_newlines_checkbox").prop("checked", power_user.keep_newlines); $("#include_newline_checkbox").prop("checked", power_user.include_newline);
$('#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);
@ -860,20 +860,20 @@ $(document).ready(() => {
saveSettingsDebounced(); saveSettingsDebounced();
}); });
// keep newlines is the child of trim sentences // include newline is the child of trim sentences
// if keep newlines is checked, trim sentences must be checked // if include newline is checked, trim sentences must be checked
// if trim sentences is unchecked, keep newlines must be unchecked // if trim sentences is unchecked, include newline must be unchecked
$("#trim_sentences_checkbox").change(function() { $("#trim_sentences_checkbox").change(function() {
power_user.trim_sentences = !!$(this).prop("checked"); power_user.trim_sentences = !!$(this).prop("checked");
if (!$(this).prop("checked")) { if (!$(this).prop("checked")) {
$("#keep_newlines_checkbox").prop("checked", false); $("#include_newline_checkbox").prop("checked", false);
power_user.keep_newlines = false; power_user.include_newline = false;
} }
saveSettingsDebounced(); saveSettingsDebounced();
}); });
$("#keep_newlines_checkbox").change(function() { $("#include_newline_checkbox").change(function() {
power_user.keep_newlines = !!$(this).prop("checked"); power_user.include_newline = !!$(this).prop("checked");
if ($(this).prop("checked")) { if ($(this).prop("checked")) {
$("#trim_sentences_checkbox").prop("checked", true); $("#trim_sentences_checkbox").prop("checked", true);
power_user.trim_sentences = true; power_user.trim_sentences = true;

View File

@ -190,19 +190,19 @@ export function sortByCssOrder(a, b) {
return _a - _b; return _a - _b;
} }
export function end_trim_to_sentence(input, keep_newlines = false) { export function end_trim_to_sentence(input, include_newline = false) {
// inspired from https://github.com/kaihordewebui/kaihordewebui.github.io/blob/06b95e6b7720eb85177fbaf1a7f52955d7cdbc02/index.html#L4853-L4867 // inspired from https://github.com/kaihordewebui/kaihordewebui.github.io/blob/06b95e6b7720eb85177fbaf1a7f52955d7cdbc02/index.html#L4853-L4867
const punctuation = new Set(['.', '!', '?']); // extend this as you see fit const punctuation = new Set(['.', '!', '?']); // extend this as you see fit
for (let i = input.length - 1; i >= 0; i--) { for (let i = input.length - 1; i >= 0; i--) {
const char = input[i]; const char = input[i];
if (punctuation.has(char)) { if (punctuation.has(char)) {
last = i; last = i;
break; break;
} }
if (include_newline && char === '\n') { if (include_newline && char === '\n') {
last = i; last = i;
break; break;