Commit 4ea62ea2c1
Unsigned
Layout: unified · split
internal/selection_menu.go +61 −48
| @@ -428,51 +428,64 @@ func RofiSelect(options map[string]string, addanimeopt bool) (SelectionOption, e | |||
| 428 | 428 | ||
| 429 | // DynamicSelect displays a simple selection prompt without extra features | 429 | // DynamicSelect displays a simple selection prompt without extra features |
| 430 | func DynamicSelect(options map[string]string, addnewoption bool) (SelectionOption, error) { | 430 | func DynamicSelect(options map[string]string, addnewoption bool) (SelectionOption, error) { |
| 431 | if GetGlobalConfig().RofiSelection { | 431 | if GetGlobalConfig().RofiSelection { |
| 432 | return RofiSelect(options, addnewoption) | 432 | return RofiSelect(options, addnewoption) |
| 433 | } | 433 | } |
| 434 | 434 | ||
| 435 | // Create a slice to maintain order | 435 | // Create a slice to maintain order |
| 436 | var orderedOptions []SelectionOption | 436 | var orderedOptions []SelectionOption |
| 437 | for key, value := range options { | 437 | |
| 438 | orderedOptions = append(orderedOptions, SelectionOption{ | 438 | // If this is a category selection (contains menu items), use the ordered keys |
| 439 | Key: key, | 439 | if _, hasMenu := options["ALL"]; hasMenu { |
| 440 | Label: value, | 440 | // Get ordered keys from the options map |
| 441 | }) | 441 | for key, value := range options { |
| 442 | } | 442 | orderedOptions = append(orderedOptions, SelectionOption{ |
| 443 | 443 | Key: key, | |
| 444 | model := &Model{ | 444 | Label: value, |
| 445 | options: options, | 445 | }) |
| 446 | filteredKeys: orderedOptions, | 446 | } |
| 447 | addNewOption: addnewoption, | 447 | } else { |
| 448 | } | 448 | // For other selections, maintain alphabetical order |
| 449 | 449 | for key, value := range options { | |
| 450 | if addnewoption { | 450 | orderedOptions = append(orderedOptions, SelectionOption{ |
| 451 | model.filteredKeys = append(model.filteredKeys, SelectionOption{ | 451 | Key: key, |
| 452 | Label: "Add new anime", | 452 | Label: value, |
| 453 | Key: "add_new", | 453 | }) |
| 454 | }) | 454 | } |
| 455 | } | 455 | } |
| 456 | 456 | ||
| 457 | model.filteredKeys = append(model.filteredKeys, SelectionOption{ | 457 | model := &Model{ |
| 458 | Label: "Quit", | 458 | options: options, |
| 459 | Key: "-1", | 459 | filteredKeys: orderedOptions, |
| 460 | }) | 460 | addNewOption: addnewoption, |
| 461 | 461 | } | |
| 462 | p := tea.NewProgram(model) | 462 | |
| 463 | 463 | if addnewoption { | |
| 464 | finalModel, err := p.Run() | 464 | model.filteredKeys = append(model.filteredKeys, SelectionOption{ |
| 465 | if err != nil { | 465 | Label: "Add new anime", |
| 466 | return SelectionOption{}, err | 466 | Key: "add_new", |
| 467 | } | 467 | }) |
| 468 | 468 | } | |
| 469 | finalSelectionModel, ok := finalModel.(*Model) | 469 | |
| 470 | if !ok { | 470 | model.filteredKeys = append(model.filteredKeys, SelectionOption{ |
| 471 | return SelectionOption{}, fmt.Errorf("unexpected model type") | 471 | Label: "Quit", |
| 472 | } | 472 | Key: "-1", |
| 473 | 473 | }) | |
| 474 | if finalSelectionModel.selected < len(finalSelectionModel.filteredKeys) { | 474 | |
| 475 | return finalSelectionModel.filteredKeys[finalSelectionModel.selected], nil | 475 | p := tea.NewProgram(model) |
| 476 | } | 476 | |
| 477 | return SelectionOption{}, nil | 477 | finalModel, err := p.Run() |
| 478 | } | 478 | if err != nil { |
| 479 | return SelectionOption{}, err | ||
| 480 | } | ||
| 481 | |||
| 482 | finalSelectionModel, ok := finalModel.(*Model) | ||
| 483 | if !ok { | ||
| 484 | return SelectionOption{}, fmt.Errorf("unexpected model type") | ||
| 485 | } | ||
| 486 | |||
| 487 | if finalSelectionModel.selected < len(finalSelectionModel.filteredKeys) { | ||
| 488 | return finalSelectionModel.filteredKeys[finalSelectionModel.selected], nil | ||
| 489 | } | ||
| 490 | return SelectionOption{}, nil | ||
| 491 | }\ No newline at end of file | ||