diff --git a/public/scripts/extensions/quick-reply/index.js b/public/scripts/extensions/quick-reply/index.js index 34b8c7d8a..6e3639ff1 100644 --- a/public/scripts/extensions/quick-reply/index.js +++ b/public/scripts/extensions/quick-reply/index.js @@ -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 () => { Disable Send / Insert In User Input +
@@ -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);