Quick-reply enhancements +fix (#1118)

* Update index.js

* change manual replace to substituteParams

* Update index.js
This commit is contained in:
IkariDevGIT 2023-09-08 20:38:31 +02:00 committed by GitHub
parent 26ddfd1a08
commit 786b87952e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 4 deletions

View File

@ -1,4 +1,4 @@
import { saveSettingsDebounced, callPopup, getRequestHeaders } from "../../../script.js";
import { saveSettingsDebounced, callPopup, getRequestHeaders, substituteParams } from "../../../script.js";
import { getContext, extension_settings } from "../../extensions.js";
import { initScrollHeight, resetScrollHeight } from "../../utils.js";
import { executeSlashCommands, getSlashCommandsHelp, registerSlashCommand } from "../../slash-commands.js";
@ -15,6 +15,8 @@ const defaultSettings = {
quickReplyEnabled: false,
numberOfSlots: 5,
quickReplySlots: [],
placeBeforePromptEnabled: false,
quickActionEnabled: false,
}
//method from worldinfo
@ -75,6 +77,8 @@ async function loadSettings(type) {
$('#quickReplyEnabled').prop('checked', extension_settings.quickReply.quickReplyEnabled);
$('#quickReplyNumberOfSlots').val(extension_settings.quickReply.numberOfSlots);
$('#placeBeforePromptEnabled').prop('checked', extension_settings.quickReply.placeBeforePromptEnabled);
$('#quickActionEnabled').prop('checked', extension_settings.quickReply.quickActionEnabled);
}
function onQuickReplyInput(id) {
@ -101,7 +105,12 @@ async function onQuickReplyEnabledInput() {
// New function to handle input on quickActionEnabled
async function onQuickActionEnabledInput() {
extension_settings.quickReply.quickActionEnabled = $(this).prop('checked');
extension_settings.quickReply.quickActionEnabled = !!$(this).prop('checked');
saveSettingsDebounced();
}
async function onPlaceBeforePromptEnabledInput() {
extension_settings.quickReply.placeBeforePromptEnabled = !!$(this).prop('checked');
saveSettingsDebounced();
}
@ -118,12 +127,18 @@ async function sendQuickReply(index) {
if (existingText) {
// If existing text, add space after prompt
newText = existingText + ' ' + prompt + ' ';
if (extension_settings.quickReply.placeBeforePromptEnabled) {
newText = `${prompt} ${existingText} `;
} else {
newText = `${existingText} ${prompt} `;
}
} else {
// If no existing text, add prompt only (with a trailing space)
newText = prompt + ' ';
}
newText = substituteParams(newText);
$("#send_textarea").val(newText);
// Set the focus back to the textarea
@ -131,7 +146,7 @@ async function sendQuickReply(index) {
// Only trigger send button if quickActionEnabled is not checked or
// the prompt starts with '/'
if (!$("#quickActionEnabled").prop('checked') || prompt.startsWith('/')) {
if (!extension_settings.quickReply.quickActionEnabled || prompt.startsWith('/')) {
$("#send_but").trigger('click');
}
}
@ -339,6 +354,10 @@ jQuery(async () => {
<input id="quickActionEnabled" type="checkbox" />
Disable Send / Insert In User Input
</label>
<label class="checkbox_label marginBot10 wide100p flexnowrap">
<input id="placeBeforePromptEnabled" type="checkbox" />
Place Quick-reply before the Prompt
</label>
<div class="flex-container flexnowrap wide100p">
<select id="quickReplyPresets" name="quickreply-preset">
</select>
@ -363,6 +382,7 @@ jQuery(async () => {
// Add event handler for quickActionEnabled
$('#quickActionEnabled').on('input', onQuickActionEnabledInput);
$('#placeBeforePromptEnabled').on('input', onPlaceBeforePromptEnabledInput);
$('#quickReplyEnabled').on('input', onQuickReplyEnabledInput);
$('#quickReplyNumberOfSlotsApply').on('click', onQuickReplyNumberOfSlotsInput);
$("#quickReplyPresetSaveButton").on('click', saveQuickReplyPreset);