fix bug in textarea cli options auto triggering complete on enter even if nothing is written

This commit is contained in:
arabcoders 2025-08-21 23:26:24 +03:00
parent 3ebd66fd60
commit cde6d956bb

View file

@ -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)
}