mirror of
https://github.com/Eugeny/tabby.git
synced 2025-09-24 17:16:03 +00:00
fix(core/selector): avoid selectedIndex to go NaN if filteredOptions empty
This commit is contained in:
@@ -29,6 +29,9 @@ export class SelectorModalComponent<T> {
|
||||
}
|
||||
|
||||
@HostListener('keydown', ['$event']) onKeyUp (event: KeyboardEvent): void {
|
||||
if (event.key === 'Escape') {
|
||||
this.close()
|
||||
} else if (this.filteredOptions.length > 0) {
|
||||
if (event.key === 'PageUp' || event.key === 'ArrowUp' && event.metaKey) {
|
||||
this.selectedIndex -= 10
|
||||
event.preventDefault()
|
||||
@@ -43,21 +46,20 @@ export class SelectorModalComponent<T> {
|
||||
event.preventDefault()
|
||||
} else if (event.key === 'Enter') {
|
||||
this.selectOption(this.filteredOptions[this.selectedIndex])
|
||||
} else if (event.key === 'Escape') {
|
||||
this.close()
|
||||
}
|
||||
if (event.key === 'Backspace' && this.canEditSelected()) {
|
||||
} else if (event.key === 'Backspace' && this.canEditSelected()) {
|
||||
event.preventDefault()
|
||||
this.filter = this.filteredOptions[this.selectedIndex].freeInputEquivalent!
|
||||
this.onFilterChange()
|
||||
}
|
||||
|
||||
this.selectedIndex = (this.selectedIndex + this.filteredOptions.length) % this.filteredOptions.length
|
||||
|
||||
Array.from(this.itemChildren)[this.selectedIndex]?.nativeElement.scrollIntoView({
|
||||
behavior: 'smooth',
|
||||
block: 'nearest',
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
onFilterChange (): void {
|
||||
const f = this.filter.trim().toLowerCase()
|
||||
|
Reference in New Issue
Block a user