From 471203924580deb6c95baccab638687d3b541a5e Mon Sep 17 00:00:00 2001 From: Massi-X Date: Sat, 30 Nov 2024 01:15:00 +0100 Subject: [PATCH 1/2] Keep highlight in select mode Keep highlighted suggestion (dropdown) in the same place after selection with the keyboard --- src/parts/suggestions.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/parts/suggestions.js b/src/parts/suggestions.js index a6354f3f..73c11b9d 100644 --- a/src/parts/suggestions.js +++ b/src/parts/suggestions.js @@ -111,9 +111,24 @@ export default { .then(() => { if( selectedElm ){ this.dropdown.selectOption(selectedElm) - // highlight next option - selectedElm = this.dropdown.getNextOrPrevOption(selectedElm, !actionUp) - this.dropdown.highlightOption(selectedElm) + + if (!isSelectMode) { // highlight next option + selectedElm = this.dropdown.getNextOrPrevOption(selectedElm, !actionUp) + this.dropdown.highlightOption(selectedElm) + } else { // in select mode this never worked. It is also better to keep the highlight in the same spot after selection + setTimeout(() => { + let refs = this.dropdown.getAllSuggestionsRefs() + let selectedElm = null + refs.forEach(elem => { + if (elem.getAttribute('value') == selectedElmData.value) { + selectedElm = elem + return + } + }) + + selectedElm != null && this.dropdown.highlightOption(selectedElm, true) + }, 0, selectedElmData) //wait for the dropdown to be redrawn + } return } else From b1f699d668c1d4cd215b4091ee4c4d97f89bb427 Mon Sep 17 00:00:00 2001 From: Massi-X <7504132+Massi-X@users.noreply.github.com> Date: Sat, 7 Dec 2024 14:24:50 +0100 Subject: [PATCH 2/2] Prevent undefined exceptions --- src/parts/suggestions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/parts/suggestions.js b/src/parts/suggestions.js index 73c11b9d..d1040096 100644 --- a/src/parts/suggestions.js +++ b/src/parts/suggestions.js @@ -120,7 +120,7 @@ export default { let refs = this.dropdown.getAllSuggestionsRefs() let selectedElm = null refs.forEach(elem => { - if (elem.getAttribute('value') == selectedElmData.value) { + if (selectedElmData && elem.getAttribute('value') == selectedElmData.value) { selectedElm = elem return } @@ -509,4 +509,4 @@ export default { return this.settings.templates.dropdownItem.apply(this, [{...suggestion, mappedValue}, this]) }).join("") } -} \ No newline at end of file +}