From 871d7746a6da4d880fd4ef02bc228d45ffddba30 Mon Sep 17 00:00:00 2001 From: mic Date: Mon, 14 Oct 2024 22:21:15 +0200 Subject: [PATCH] autocomplete. closing suggestions when clicking outside the list. see #157 --- customprompts/mzta-custom-prompts.html | 2 +- customprompts/mzta-custom-prompts.js | 37 ++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/customprompts/mzta-custom-prompts.html b/customprompts/mzta-custom-prompts.html index 513ec5e9..6293cac8 100644 --- a/customprompts/mzta-custom-prompts.html +++ b/customprompts/mzta-custom-prompts.html @@ -42,7 +42,7 @@
- diff --git a/customprompts/mzta-custom-prompts.js b/customprompts/mzta-custom-prompts.js index 443fc8b0..9a571fe9 100644 --- a/customprompts/mzta-custom-prompts.js +++ b/customprompts/mzta-custom-prompts.js @@ -118,7 +118,21 @@ document.addEventListener('DOMContentLoaded', async () => { // console.log('>>>>>>>>>>> suggestions: ' + JSON.stringify(suggestions)); - textareas.forEach(textarea => textareaAutocomplete(textarea, autocompleteSuggestions)); + textareas.forEach(textarea => textareaAutocomplete(textarea, autocompleteSuggestions, textarea.closest('.type_selector')?.value)); + + // document.addEventListener('click', (e) => { + // // Check if the click was outside the textarea or suggestion list + // const isClickInsideTextarea = e.target.closest('.editor'); + // const isClickInsideAutocompleteList = e.target.closest('.autocomplete-list'); + + // if (!isClickInsideTextarea && !isClickInsideAutocompleteList) { + // textareas.forEach(textarea => { + // const container = textarea.closest('.autocomplete-container'); + // const autocompleteList = container.querySelector('.autocomplete-list'); + // hideSuggestions(autocompleteList); + // }); + // } + // }); i18n.updateDocument(); @@ -285,7 +299,7 @@ function showItemRowEditor(tr) { tr.querySelector('.name_show').style.display = 'none'; const text_output = tr.querySelector('.text_output'); text_output.style.display = 'inline'; - textareaAutocomplete(text_output, autocompleteSuggestions) + textareaAutocomplete(text_output, autocompleteSuggestions, tr.closest('.type_selector').value) tr.querySelector('.text_show').style.display = 'none'; tr.querySelector('.type_output').style.display = 'inline'; tr.querySelector('.type_show').style.display = 'none'; @@ -411,7 +425,7 @@ function loadPromptsList(values){
- ` + type_output + ` + ` + type_output + `