From 57e45b3df8eb4da9e694bfe6a51023d90750aaec Mon Sep 17 00:00:00 2001 From: mic Date: Tue, 15 Oct 2024 22:14:54 +0200 Subject: [PATCH] better autocomplete keyboard interaction. see #157 --- customprompts/mzta-custom-prompts.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/customprompts/mzta-custom-prompts.js b/customprompts/mzta-custom-prompts.js index a38ef1a2..34930c0f 100644 --- a/customprompts/mzta-custom-prompts.js +++ b/customprompts/mzta-custom-prompts.js @@ -701,6 +701,9 @@ function textareaAutocomplete(textarea, suggestions) { }); textarea.addEventListener('keydown', (e) => { + if (autocompleteList.classList.contains('hidden')) { + return; + } const items = autocompleteList.querySelectorAll('li'); if (items.length > 0) { if (e.key === 'ArrowDown') { @@ -713,6 +716,7 @@ function textareaAutocomplete(textarea, suggestions) { updateActiveSuggestion(items, activeIndex); } else if (e.key === 'Enter') { e.preventDefault(); + if(activeIndex === -1) activeIndex = 0; if (activeIndex >= 0 && activeIndex < items.length) { insertAutocomplete(items[activeIndex].textContent, textarea); hideSuggestions(autocompleteList);