allow directly editing items from the profile selector - fixes #6039

This commit is contained in:
Eugene Pankov
2022-04-15 19:45:30 +02:00
parent 358a7563f6
commit 7016688170
6 changed files with 36 additions and 3 deletions

View File

@@ -27,7 +27,7 @@ export class SelectorModalComponent<T> {
this.hasGroups = this.options.some(x => x.group)
}
@HostListener('keyup', ['$event']) onKeyUp (event: KeyboardEvent): void {
@HostListener('keydown', ['$event']) onKeyUp (event: KeyboardEvent): void {
if (event.key === 'ArrowUp') {
this.selectedIndex--
event.preventDefault()
@@ -42,6 +42,10 @@ export class SelectorModalComponent<T> {
if (event.key === 'Escape') {
this.close()
}
if (event.key === 'Backspace' && this.canEditSelected()) {
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({
@@ -85,6 +89,10 @@ export class SelectorModalComponent<T> {
this.modalInstance.close(option.result)
}
canEditSelected (): boolean {
return !this.filter && !!this.filteredOptions[this.selectedIndex].freeInputEquivalent && this.options.some(x => x.freeInputPattern)
}
close (): void {
this.modalInstance.dismiss()
}