Configurable chat truncation amount

This commit is contained in:
Cohee 2023-11-19 21:57:54 +02:00
parent a02446c4cc
commit ac07c8324d
4 changed files with 33 additions and 7 deletions

View File

@ -2756,6 +2756,19 @@
</div> </div>
</div> </div>
</div> </div>
<div id="chat-truncation-block" class="range-block">
<div class="range-block-title" data-i18n="Chat Truncation">
Chat Truncation <small>(0 = unlimited)</small>
</div>
<div class="range-block-range-and-counter">
<div class="range-block-range">
<input type="range" id="chat_truncation" name="chat_truncation" min="0" max="1000" step="25">
</div>
<div class="range-block-counter">
<input type="number" min="0" max="1000" step="1" data-for="chat_truncation" id="chat_truncation_counter">
</div>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -1297,11 +1297,9 @@ async function replaceCurrentChat() {
} }
} }
const TRUNCATION_THRESHOLD = 100;
export function showMoreMessages() { export function showMoreMessages() {
let messageId = Number($('#chat').children('.mes').first().attr('mesid')); let messageId = Number($('#chat').children('.mes').first().attr('mesid'));
let count = TRUNCATION_THRESHOLD; let count = power_user.chat_truncation || Number.MAX_SAFE_INTEGER;
console.debug('Inserting messages before', messageId, 'count', count, 'chat length', chat.length); console.debug('Inserting messages before', messageId, 'count', count, 'chat length', chat.length);
const prevHeight = $('#chat').prop('scrollHeight'); const prevHeight = $('#chat').prop('scrollHeight');
@ -1322,9 +1320,10 @@ export function showMoreMessages() {
async function printMessages() { async function printMessages() {
let startIndex = 0; let startIndex = 0;
let count = power_user.chat_truncation || Number.MAX_SAFE_INTEGER;
if (chat.length > TRUNCATION_THRESHOLD) { if (chat.length > count) {
count_view_mes = chat.length - TRUNCATION_THRESHOLD; count_view_mes = chat.length - count;
startIndex = count_view_mes; startIndex = count_view_mes;
$('#chat').append('<div id="show_more_messages">Show more messages</div>'); $('#chat').append('<div id="show_more_messages">Show more messages</div>');
} }

View File

@ -107,6 +107,7 @@ let power_user = {
target_length: 400, target_length: 400,
}, },
markdown_escape_strings: '', markdown_escape_strings: '',
chat_truncation: 100,
ui_mode: ui_mode.POWER, ui_mode: ui_mode.POWER,
fast_ui_mode: true, fast_ui_mode: true,
@ -1373,6 +1374,9 @@ function loadPowerUserSettings(settings, data) {
$("#token_padding").val(power_user.token_padding); $("#token_padding").val(power_user.token_padding);
$("#aux_field").val(power_user.aux_field); $("#aux_field").val(power_user.aux_field);
$("#chat_truncation").val(power_user.chat_truncation);
$('#chat_truncation_counter').val(power_user.chat_truncation);
$("#font_scale").val(power_user.font_scale); $("#font_scale").val(power_user.font_scale);
$("#font_scale_counter").val(power_user.font_scale); $("#font_scale_counter").val(power_user.font_scale);
@ -2559,6 +2563,12 @@ $(document).ready(() => {
setHotswapsDebounced(); setHotswapsDebounced();
}); });
$('#chat_truncation').on('input', function () {
power_user.chat_truncation = Number($('#chat_truncation').val());
$('#chat_truncation_counter').val(power_user.chat_truncation);
saveSettingsDebounced();
});
$(`input[name="font_scale"]`).on('input', async function (e) { $(`input[name="font_scale"]`).on('input', async function (e) {
power_user.font_scale = Number(e.target.value); power_user.font_scale = Number(e.target.value);
$("#font_scale_counter").val(power_user.font_scale); $("#font_scale_counter").val(power_user.font_scale);

View File

@ -3730,11 +3730,15 @@ a {
#show_more_messages { #show_more_messages {
text-align: center; text-align: center;
margin: 10px 0; margin: 10px auto;
font-weight: 500; font-weight: 500;
text-decoration: underline;
order: -1; order: -1;
cursor: pointer; cursor: pointer;
padding: 0.5em 1em;
background-color: var(--SmartThemeBlurTintColor);
width: fit-content;
border-radius: 10px;
outline: 1px solid var(--SmartThemeBorderColor);
} }
.draggable img { .draggable img {