| @@ -365,12 +365,16 @@ func (m *Model) filterOptions() { |
| 365 | }) |
365 | }) |
| 366 | } |
366 | } |
| 367 | |
367 | |
| 368 | // Determine whether the current filter is a substring of the pinned labels. |
368 | // Pin Back / Add new / Quit only when the filter is empty or matches their labels. |
| 369 | // When the filter matches "back" (e.g. "b", "ba", "bac", "back"), Back should |
369 | // Previously Quit/Back were always forced visible, so "/quit" still showed Back first |
| 370 | // appear BEFORE "Add new anime" so it is easy to reach. Otherwise keep the |
370 | // and Enter could select the wrong row. |
| 371 | // default order: Add new anime → Back → Quit. |
371 | filterLower := strings.ToLower(strings.TrimSpace(m.filter)) |
| 372 | // All three pinned items are always shown regardless of filter text. |
372 | pinMatches := func(label string) bool { |
| 373 | filterLower := strings.ToLower(m.filter) |
373 | if filterLower == "" { |
| |
374 | return true |
| |
375 | } |
| |
376 | return strings.Contains(strings.ToLower(label), filterLower) |
| |
377 | } |
| 374 | backMatchesFilter := filterLower != "" && strings.Contains("back", filterLower) |
378 | backMatchesFilter := filterLower != "" && strings.Contains("back", filterLower) |
| 375 | |
379 | |
| 376 | // If filter targets "back", pin it above Add new anime |
380 | // If filter targets "back", pin it above Add new anime |
| @@ -378,19 +382,20 @@ func (m *Model) filterOptions() { |
| 378 | m.filteredKeys = append(m.filteredKeys, SelectionOption{Label: "Back", Key: "-2"}) |
382 | m.filteredKeys = append(m.filteredKeys, SelectionOption{Label: "Back", Key: "-2"}) |
| 379 | } |
383 | } |
| 380 | |
384 | |
| 381 | // Add new anime is always shown (pinned) |
385 | // Add new anime when unfiltered or filter matches |
| 382 | if m.addNewOption { |
386 | if m.addNewOption && pinMatches("Add new anime") { |
| 383 | |
| |
| 384 | m.filteredKeys = append(m.filteredKeys, SelectionOption{Label: "Add new anime", Key: "add_new"}) |
387 | m.filteredKeys = append(m.filteredKeys, SelectionOption{Label: "Add new anime", Key: "add_new"}) |
| 385 | } |
388 | } |
| 386 | |
389 | |
| 387 | // Back in its default position (after Add new anime) when filter doesn't target it |
390 | // Back in its default position when unfiltered (or filter matches "back" handled above) |
| 388 | if !m.isHomeMenu && !backMatchesFilter { |
391 | if !m.isHomeMenu && !backMatchesFilter && pinMatches("Back") { |
| 389 | m.filteredKeys = append(m.filteredKeys, SelectionOption{Label: "Back", Key: "-2"}) |
392 | m.filteredKeys = append(m.filteredKeys, SelectionOption{Label: "Back", Key: "-2"}) |
| 390 | } |
393 | } |
| 391 | |
394 | |
| 392 | // Quit is always last |
395 | // Quit last — only when unfiltered or filter matches "quit" |
| 393 | m.filteredKeys = append(m.filteredKeys, SelectionOption{Label: "Quit", Key: "-1"}) |
396 | if pinMatches("Quit") { |
| |
397 | m.filteredKeys = append(m.filteredKeys, SelectionOption{Label: "Quit", Key: "-1"}) |
| |
398 | } |
| 394 | } |
399 | } |
| 395 | |
400 | |
| 396 | func detectHomeMenu(options []SelectionOption) bool { |
401 | func detectHomeMenu(options []SelectionOption) bool { |