fix bug in textarea cli options auto triggering complete on enter even if nothing is written
This commit is contained in:
parent
3ebd66fd60
commit
cde6d956bb
1 changed files with 6 additions and 3 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue