From b81ccb4ee33240d857d8fd059921bb2b5975ea6c Mon Sep 17 00:00:00 2001 From: Anwarul Islam Date: Tue, 23 Jan 2024 22:21:23 +0530 Subject: [PATCH] fix: tab on current input field to focus the next input field (#3754) --- .../src/components/smart/EnvInput.vue | 60 +++++++++---------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/packages/hoppscotch-common/src/components/smart/EnvInput.vue b/packages/hoppscotch-common/src/components/smart/EnvInput.vue index 1868dc131..f2a899f4f 100644 --- a/packages/hoppscotch-common/src/components/smart/EnvInput.vue +++ b/packages/hoppscotch-common/src/components/smart/EnvInput.vue @@ -37,7 +37,7 @@ v-if="currentSuggestionIndex === index" class="hidden items-center text-secondary md:flex" > - TAB + Enter to select @@ -169,36 +169,41 @@ watch( ) const handleKeystroke = (ev: KeyboardEvent) => { - if (["ArrowDown", "ArrowUp", "Enter", "Tab", "Escape"].includes(ev.key)) { + if (!props.autoCompleteSource) return + + if (["ArrowDown", "ArrowUp", "Enter", "Escape"].includes(ev.key)) { ev.preventDefault() } - if (ev.shiftKey) { + if (["Escape", "Tab", "Shift"].includes(ev.key)) { showSuggestionPopover.value = false - return } - showSuggestionPopover.value = true + if (ev.key === "Enter") { + if (suggestions.value.length > 0 && currentSuggestionIndex.value > -1) { + updateModelValue(suggestions.value[currentSuggestionIndex.value]) + currentSuggestionIndex.value = -1 - if ( - ["Enter", "Tab"].includes(ev.key) && - suggestions.value.length > 0 && - currentSuggestionIndex.value > -1 - ) { - updateModelValue(suggestions.value[currentSuggestionIndex.value]) - currentSuggestionIndex.value = -1 - - //used to set codemirror cursor at the end of the line after selecting a suggestion - nextTick(() => { - view.value?.dispatch({ - selection: EditorSelection.create([ - EditorSelection.range( - props.modelValue.length, - props.modelValue.length - ), - ]), + //used to set codemirror cursor at the end of the line after selecting a suggestion + nextTick(() => { + view.value?.dispatch({ + selection: EditorSelection.create([ + EditorSelection.range( + props.modelValue.length, + props.modelValue.length + ), + ]), + }) }) - }) + } + + if (showSuggestionPopover.value) { + showSuggestionPopover.value = false + } else { + emit("enter", ev) + } + } else { + showSuggestionPopover.value = true } if (ev.key === "ArrowDown") { @@ -223,15 +228,6 @@ const handleKeystroke = (ev: KeyboardEvent) => { emit("keyup", ev) } - if (ev.key === "Enter") { - emit("enter", ev) - showSuggestionPopover.value = false - } - - if (ev.key === "Escape") { - showSuggestionPopover.value = false - } - // used to scroll to the first suggestion when left arrow is pressed if (ev.key === "ArrowLeft") { if (suggestions.value.length > 0) {