From 3759ec055a0486cc345f5d989af2438607d7a447 Mon Sep 17 00:00:00 2001 From: Dominik Reh Date: Sat, 22 Oct 2022 13:23:16 +0200 Subject: [PATCH] Allow autocomplete with Tab key Closes #29 --- javascript/tagAutocomplete.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/javascript/tagAutocomplete.js b/javascript/tagAutocomplete.js index 356a0d7..b8365dd 100644 --- a/javascript/tagAutocomplete.js +++ b/javascript/tagAutocomplete.js @@ -465,7 +465,7 @@ function navigateInList(textArea, event) { // Return if the function is deactivated in the UI if (!acActive) return; - validKeys = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Enter", "Escape"]; + validKeys = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Enter", "Tab", "Escape"]; if (!validKeys.includes(event.key)) return; if (!isVisible(textArea)) return @@ -500,11 +500,17 @@ function navigateInList(textArea, event) { insertTextAtCursor(textArea, results[selectedTag], tagword); } break; + case "Tab": + if (selectedTag === null) { + selectedTag = 0; + } + insertTextAtCursor(textArea, results[selectedTag], tagword); + break; case "Escape": hideResults(textArea); break; } - if (selectedTag == resultCount - 1 + if (selectedTag === resultCount - 1 && (event.key === "ArrowUp" || event.key === "ArrowDown" || event.key === "ArrowLeft" || event.key === "ArrowRight")) { addResultsToList(textArea, results, tagword, false); }