mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add /chat-render and /chat-reload commands
This commit is contained in:
@ -167,6 +167,7 @@ import {
|
|||||||
flashHighlight,
|
flashHighlight,
|
||||||
isTrueBoolean,
|
isTrueBoolean,
|
||||||
toggleDrawer,
|
toggleDrawer,
|
||||||
|
isElementInViewport,
|
||||||
} from './scripts/utils.js';
|
} from './scripts/utils.js';
|
||||||
import { debounce_timeout } from './scripts/constants.js';
|
import { debounce_timeout } from './scripts/constants.js';
|
||||||
|
|
||||||
@ -1827,10 +1828,10 @@ export async function replaceCurrentChat() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function showMoreMessages() {
|
export function showMoreMessages(messagesToLoad = null) {
|
||||||
const firstDisplayedMesId = $('#chat').children('.mes').first().attr('mesid');
|
const firstDisplayedMesId = $('#chat').children('.mes').first().attr('mesid');
|
||||||
let messageId = Number(firstDisplayedMesId);
|
let messageId = Number(firstDisplayedMesId);
|
||||||
let count = power_user.chat_truncation || Number.MAX_SAFE_INTEGER;
|
let count = messagesToLoad || power_user.chat_truncation || Number.MAX_SAFE_INTEGER;
|
||||||
|
|
||||||
// If there are no messages displayed, or the message somehow has no mesid, we default to one higher than last message id,
|
// If there are no messages displayed, or the message somehow has no mesid, we default to one higher than last message id,
|
||||||
// so the first "new" message being shown will be the last available message
|
// so the first "new" message being shown will be the last available message
|
||||||
@ -1840,6 +1841,7 @@ export function showMoreMessages() {
|
|||||||
|
|
||||||
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');
|
||||||
|
const isButtonInView = isElementInViewport($('#show_more_messages')[0]);
|
||||||
|
|
||||||
while (messageId > 0 && count > 0) {
|
while (messageId > 0 && count > 0) {
|
||||||
let newMessageId = messageId - 1;
|
let newMessageId = messageId - 1;
|
||||||
@ -1852,8 +1854,10 @@ export function showMoreMessages() {
|
|||||||
$('#show_more_messages').remove();
|
$('#show_more_messages').remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
const newHeight = $('#chat').prop('scrollHeight');
|
if (isButtonInView) {
|
||||||
$('#chat').scrollTop(newHeight - prevHeight);
|
const newHeight = $('#chat').prop('scrollHeight');
|
||||||
|
$('#chat').scrollTop(newHeight - prevHeight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function printMessages() {
|
export async function printMessages() {
|
||||||
|
@ -39,6 +39,7 @@ import {
|
|||||||
setCharacterName,
|
setCharacterName,
|
||||||
setExtensionPrompt,
|
setExtensionPrompt,
|
||||||
setUserName,
|
setUserName,
|
||||||
|
showMoreMessages,
|
||||||
stopGeneration,
|
stopGeneration,
|
||||||
substituteParams,
|
substituteParams,
|
||||||
system_avatar,
|
system_avatar,
|
||||||
@ -1964,6 +1965,27 @@ export function initDefaultSlashCommands() {
|
|||||||
returns: ARGUMENT_TYPE.BOOLEAN,
|
returns: ARGUMENT_TYPE.BOOLEAN,
|
||||||
helpString: 'Returns true if the current device is a mobile device, false otherwise. Equivalent to <code>{{isMobile}}</code> macro.',
|
helpString: 'Returns true if the current device is a mobile device, false otherwise. Equivalent to <code>{{isMobile}}</code> macro.',
|
||||||
}));
|
}));
|
||||||
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||||
|
name: 'chat-render',
|
||||||
|
helpString: 'Renders a specified number of messages into the chat window. Displays all messages if no argument is provided.',
|
||||||
|
callback: (_, number) => {
|
||||||
|
showMoreMessages(number && !isNaN(Number(number)) ? Number(number) : Number.MAX_SAFE_INTEGER);
|
||||||
|
return '';
|
||||||
|
},
|
||||||
|
unnamedArgumentList: [
|
||||||
|
new SlashCommandArgument(
|
||||||
|
'number of messages', [ARGUMENT_TYPE.NUMBER], false,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
}));
|
||||||
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||||
|
name: 'chat-reload',
|
||||||
|
helpString: 'Reloads the current chat.',
|
||||||
|
callback: async () => {
|
||||||
|
await reloadCurrentChat();
|
||||||
|
return '';
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
registerVariableCommands();
|
registerVariableCommands();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user