mirror of
https://github.com/Eugeny/tabby.git
synced 2025-06-22 04:19:54 +00:00
fix(core): selector prevent edit selection on keydown
This commit is contained in:
parent
3ce2bb68c6
commit
651861cd4a
@ -18,17 +18,18 @@ export class SelectorModalComponent<T> {
|
|||||||
@Input() selectedIndex = 0
|
@Input() selectedIndex = 0
|
||||||
hasGroups = false
|
hasGroups = false
|
||||||
@ViewChildren('item') itemChildren: QueryList<ElementRef>
|
@ViewChildren('item') itemChildren: QueryList<ElementRef>
|
||||||
|
private preventEdit: boolean
|
||||||
|
|
||||||
constructor (
|
constructor (public modalInstance: NgbActiveModal) {
|
||||||
public modalInstance: NgbActiveModal,
|
this.preventEdit = false
|
||||||
) { }
|
}
|
||||||
|
|
||||||
ngOnInit (): void {
|
ngOnInit (): void {
|
||||||
this.onFilterChange()
|
this.onFilterChange()
|
||||||
this.hasGroups = this.options.some(x => x.group)
|
this.hasGroups = this.options.some(x => x.group)
|
||||||
}
|
}
|
||||||
|
|
||||||
@HostListener('keydown', ['$event']) onKeyUp (event: KeyboardEvent): void {
|
@HostListener('keydown', ['$event']) onKeyDown (event: KeyboardEvent): void {
|
||||||
if (event.key === 'Escape') {
|
if (event.key === 'Escape') {
|
||||||
this.close()
|
this.close()
|
||||||
} else if (this.filteredOptions.length > 0) {
|
} else if (this.filteredOptions.length > 0) {
|
||||||
@ -46,10 +47,14 @@ export class SelectorModalComponent<T> {
|
|||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
} else if (event.key === 'Enter') {
|
} else if (event.key === 'Enter') {
|
||||||
this.selectOption(this.filteredOptions[this.selectedIndex])
|
this.selectOption(this.filteredOptions[this.selectedIndex])
|
||||||
} else if (event.key === 'Backspace' && this.canEditSelected()) {
|
} else if (event.key === 'Backspace' && !this.preventEdit) {
|
||||||
|
if (this.canEditSelected()) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
this.filter = this.filteredOptions[this.selectedIndex].freeInputEquivalent!
|
this.filter = this.filteredOptions[this.selectedIndex].freeInputEquivalent!
|
||||||
this.onFilterChange()
|
this.onFilterChange()
|
||||||
|
} else {
|
||||||
|
this.preventEdit = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.selectedIndex = (this.selectedIndex + this.filteredOptions.length) % this.filteredOptions.length
|
this.selectedIndex = (this.selectedIndex + this.filteredOptions.length) % this.filteredOptions.length
|
||||||
@ -61,6 +66,12 @@ export class SelectorModalComponent<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@HostListener('keyup', ['$event']) onKeyUp (event: KeyboardEvent): void {
|
||||||
|
if (event.key === 'Backspace' && this.preventEdit) {
|
||||||
|
this.preventEdit = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onFilterChange (): void {
|
onFilterChange (): void {
|
||||||
const f = this.filter.trim().toLowerCase()
|
const f = this.filter.trim().toLowerCase()
|
||||||
if (!f) {
|
if (!f) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user