From cde6d956bb0ddcfbf4facd76df89a8e991264814 Mon Sep 17 00:00:00 2001 From: arabcoders Date: Thu, 21 Aug 2025 23:26:24 +0300 Subject: [PATCH] fix bug in textarea cli options auto triggering complete on enter even if nothing is written --- ui/app/components/TextareaAutocomplete.vue | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ui/app/components/TextareaAutocomplete.vue b/ui/app/components/TextareaAutocomplete.vue index d833d3a8..93e68c03 100644 --- a/ui/app/components/TextareaAutocomplete.vue +++ b/ui/app/components/TextareaAutocomplete.vue @@ -77,8 +77,9 @@ const appendFlag = (flag: string) => { } const onInput = () => { - showList.value = true - highlightedIndex.value = filteredOptions.value.length ? 0 : -1 + const lastWord = localValue.value.split(/\s+/).pop() || '' + showList.value = lastWord.length > 0 + highlightedIndex.value = (showList.value && filteredOptions.value.length && lastWord.length > 0) ? 0 : -1 } const hideList = () => setTimeout(() => { showList.value = false; highlightedIndex.value = -1 }, 100) @@ -119,9 +120,11 @@ const onKeydown = (e: KeyboardEvent) => { if (el) el.scrollIntoView({ block: 'nearest' }) }) } else if (e.key === 'Enter' || e.key === 'Tab') { + const lastWord = localValue.value.split(/\s+/).pop() || '' const selected = highlightedIndex.value >= 0 && highlightedIndex.value < filteredOptions.value.length ? filteredOptions.value[highlightedIndex.value] : undefined - if (selected) { + // Only autocomplete if there's a partial word being typed + if (selected && lastWord.trim().length > 0) { e.preventDefault() appendFlag(selected.value) }