handleBgMenuKey drives the background picker. Up/down move between the cork toggle, the color rows, and the custom-hex row, live-previewing as they go. Left/right/space toggle cork while the cork row is focused. On the custom row, rune/backspace edit the hex buffer (valid hex previews live). Enter c
(msg tea.KeyMsg, key string)
| 467 | // row, rune/backspace edit the hex buffer (valid hex previews live). Enter |
| 468 | // commits + persists; esc reverts to the background active at open time. |
| 469 | func (m model) handleBgMenuKey(msg tea.KeyMsg, key string) (tea.Model, tea.Cmd) { |
| 470 | bm := m.bgMenu |
| 471 | preview := func() { m.workspace.Background = bm.Selected() } |
| 472 | |
| 473 | switch key { |
| 474 | case "esc": |
| 475 | m.workspace.Background = bm.Saved |
| 476 | m.bgMenu = nil |
| 477 | return m, nil |
| 478 | case "enter": |
| 479 | m.workspace.Background = bm.Selected() |
| 480 | m.saver.Touch() |
| 481 | m.setToast("background: " + bm.Label()) |
| 482 | m.bgMenu = nil |
| 483 | return m, nil |
| 484 | case "up", "ctrl+p": |
| 485 | bm.Move(-1) |
| 486 | preview() |
| 487 | return m, nil |
| 488 | case "down", "ctrl+n", "tab": |
| 489 | bm.Move(1) |
| 490 | preview() |
| 491 | return m, nil |
| 492 | case "left", "right", " ": |
| 493 | // Arrows toggle the cork overlay from anywhere in the menu. |
| 494 | bm.ToggleCork() |
| 495 | preview() |
| 496 | return m, nil |
| 497 | case "backspace": |
| 498 | if bm.OnCustom() { |
| 499 | bm.HexBackspace() |
| 500 | preview() |
| 501 | } |
| 502 | return m, nil |
| 503 | } |
| 504 | // On the custom row, hex digits (and '#') feed the input buffer. |
| 505 | if bm.OnCustom() && len(msg.Runes) > 0 { |
| 506 | bm.HexInput(msg.Runes) |
| 507 | preview() |
| 508 | return m, nil |
| 509 | } |
| 510 | // vim-style movement / cork toggle when not typing into the hex field. |
| 511 | switch key { |
| 512 | case "k": |
| 513 | bm.Move(-1) |
| 514 | preview() |
| 515 | case "j": |
| 516 | bm.Move(1) |
| 517 | preview() |
| 518 | case "h", "l": |
| 519 | bm.ToggleCork() |
| 520 | preview() |
| 521 | } |
| 522 | return m, nil |
| 523 | } |
| 524 | |
| 525 | func (m model) handleBoardKey(key string) (tea.Model, tea.Cmd) { |
| 526 | switch key { |
no test coverage detected