diff --git a/public/index.html b/public/index.html index 9e53da59f..d3cd621e2 100644 --- a/public/index.html +++ b/public/index.html @@ -6090,7 +6090,10 @@

Alternate Greetings

- +
These will be displayed as swipes on the first message when starting a new chat. @@ -6106,11 +6109,18 @@
-
- Alternate Greeting # - -
- +
+ +
+ Alternate Greeting # + +
+
+ +
diff --git a/public/script.js b/public/script.js index 0f7705b1e..06b5fc7ab 100644 --- a/public/script.js +++ b/public/script.js @@ -7390,7 +7390,7 @@ function onScenarioOverrideRemoveClick() { */ export function callPopup(text, type, inputValue = '', { okButton, rows, wide, wider, large, allowHorizontalScrolling, allowVerticalScrolling, cropAspect } = {}) { function getOkButtonText() { - if (['text', 'alternate_greeting', 'char_not_selected'].includes(popup_type)) { + if (['text', 'char_not_selected'].includes(popup_type)) { $dialoguePopupCancel.css('display', 'none'); return okButton ?? 'Ok'; } else if (['delete_extension'].includes(popup_type)) { @@ -7827,24 +7827,42 @@ function openAlternateGreetings() { const template = $('#alternate_greetings_template .alternate_grettings').clone(); const getArray = () => menu_type == 'create' ? create_save.alternate_greetings : characters[chid].data.alternate_greetings; + const popup = new Popup(template, POPUP_TYPE.TEXT, '', { + wide: true, + large: true, + allowVerticalScrolling: true, + onClose: async () => { + if (menu_type !== 'create') { + await createOrEditCharacter(); + } + } + }); for (let index = 0; index < getArray().length; index++) { - addAlternateGreeting(template, getArray()[index], index, getArray); + addAlternateGreeting(template, getArray()[index], index, getArray, popup); } template.find('.add_alternate_greeting').on('click', function () { const array = getArray(); const index = array.length; array.push(''); - addAlternateGreeting(template, '', index, getArray); + addAlternateGreeting(template, '', index, getArray, popup); updateAlternateGreetingsHintVisibility(template); }); updateAlternateGreetingsHintVisibility(template); - callPopup(template, 'alternate_greeting', '', { wide: true, large: true }); + popup.show(); } -function addAlternateGreeting(template, greeting, index, getArray) { +/** + * Adds an alternate greeting to the template. + * @param {JQuery} template + * @param {string} greeting + * @param {number} index + * @param {() => any[]} getArray + * @param {Popup} popup + */ +function addAlternateGreeting(template, greeting, index, getArray, popup) { const greetingBlock = $('#alternate_greeting_form_template .alternate_greeting').clone(); greetingBlock.find('.alternate_greeting_text').on('input', async function () { const value = $(this).val(); @@ -7852,11 +7870,16 @@ function addAlternateGreeting(template, greeting, index, getArray) { array[index] = value; }).val(greeting); greetingBlock.find('.greeting_index').text(index + 1); - greetingBlock.find('.delete_alternate_greeting').on('click', async function () { + greetingBlock.find('.delete_alternate_greeting').on('click', async function (event) { + event.preventDefault(); + event.stopPropagation(); + if (confirm('Are you sure you want to delete this alternate greeting?')) { const array = getArray(); array.splice(index, 1); + // We need to reopen the popup to update the index numbers + await popup.complete(POPUP_RESULT.AFFIRMATIVE); openAlternateGreetings(); } }); @@ -9574,9 +9597,6 @@ jQuery(async function () { }, 2000); } } - if (popup_type == 'alternate_greeting' && menu_type !== 'create') { - createOrEditCharacter(); - } if (dialogueResolve) { if (popup_type == 'input') { diff --git a/public/style.css b/public/style.css index dd716d0f6..335bff05c 100644 --- a/public/style.css +++ b/public/style.css @@ -3154,6 +3154,26 @@ grammarly-extension { align-items: center; } +.alternate_greeting details { + padding: 2px; +} + +.alternate_greeting summary { + list-style-position: outside; + margin-left: 1em; + padding-left: 1em; +} + +.alternate_greeting textarea { + field-sizing: content; + max-height: 50dvh; +} + +.alternate_greeting summary::marker, +.alternate_greeting summary strong { + cursor: pointer; +} + #rm_characters_block .form_create_bottom_buttons_block { justify-content: space-evenly !important; flex-grow: 0;