Skip to content

fix(colors): number keys and hidden separators in Edit Colors - #686

Open
eric-engberg wants to merge 2 commits into
sirmalloc:mainfrom
eric-engberg:fix/color-menu-keys
Open

eric-engberg wants to merge 2 commits into
sirmalloc:mainfrom
eric-engberg:fix/color-menu-keys

Conversation

@eric-engberg

Copy link
Copy Markdown
Contributor

What

Two key fixes in Edit Colors:

  • Number keys no longer leave the screen. Only Enter on ← Back (or ESC) goes back.
  • Hiding separators (s) while one is highlighted moves the highlight to the first widget, so the color keys and the "Current foreground" line work again.

Why

Number keys. The widget list is an ink-select-input list, which selects the item at a digit's position, the same as Enter on it. Edit Colors already skips digits in its own key handler ("Ignore number keys to prevent SelectInput numerical navigation"), but the list still passed them to onSelect, and selecting ← Back called onBack. With four widgets on a line, 5 drops you back to "Select Line to Edit Colors"; with two, 3 does.

Hidden separator. In plain mode, s shows separators so they can be colored. Show them, ↓ onto 2: Separator: |, press s again: the list redraws with ▶ on 1: Model, but the highlight still points at the hidden separator. The "Current foreground" line goes blank, b, d, r and ←/→ do nothing, and a color entered after a, h or g is dropped, until you move the highlight with ↑/↓.

How

  • The list no longer gets an onSelect; Edit Colors handles Enter in its own key handler and goes back when ← Back is highlighted. Enter on a widget still does nothing (colors cycle with ←/→), and ESC still leaves background mode first, then the screen. No other menu changes.
  • The s handler checks whether hiding takes away the highlighted separator and, if so, highlights the first widget, the item the list already draws ▶ on. Showing separators, or hiding them with a widget highlighted, keeps the highlight where it was.

Demo

The TUI's sample data. First, Edit Colors on a line with four widgets: press 5 (the Back entry's position), then ↓.

Powerline: before

Pressing 5 leaves Edit Colors for the line list, Powerline mode, before the fix

Powerline: after

Pressing 5 does nothing and the highlight then moves down, Powerline mode, after the fix

Plain: before

Pressing 5 leaves Edit Colors for the line list, plain mode, before the fix

Plain: after

Pressing 5 does nothing and the highlight then moves down, plain mode, after the fix

Then a plain line with a separator: s to show separators, ↓ onto it, s to hide them, then b and →. Plain only: Powerline mode has no separator widgets, and s does nothing there.

Plain: before

After hiding the highlighted separator, the current color is blank and b and right do nothing, before the fix

Plain: after

After hiding the highlighted separator, Model is highlighted and b and right apply to it, after the fix

Testing

  • Two new tests in ColorMenu.test.tsx, each waiting for every key's visible effect:
    • two widgets, 3, then ↓: expects the highlight on 2: Version and no onBack, then ↓ and Enter on ← Back call onBack once. Failed on main (onBack called once by the 3).
    • Model, separator, Version: s, ↓, s: expects ▶ on 1: Model and the "Current foreground" line, then b makes Model bold. Failed on main (the line was blank and b changed nothing).
    • Looped 10 times, no failures.
  • bun test: 2784 pass, 0 fail. bun run lint passes.
  • ColorMenu.test.tsx under Node 26.10.0 (Vitest): 3 pass (1 existing and 2 new); main passes its 1.
  • Built CLI under Node 26.10.0 in tmux with a scratch HOME (Model, separator, Git Branch): on main, 3 leaves for "Select Line to Edit Colors", and after hiding the separator "Current foreground" is missing and b/→ change nothing. On this branch 3 keeps the screen, the hidden separator hands the highlight to Model (Current foreground (8/17): Cyan), b and → apply (White [BOLD]), and Enter on ← Back still leaves.
  • Bun 1.4.2.

ink-select-input selects the item at a digit key's position, the same as
Enter on it. Edit Colors ignored digits in its own key handler, but its
list still passed them to onSelect, and choosing the Back entry there
called onBack. So on a line with two colorable widgets, pressing 3 left
the screen; with eight, 9 did.

Edit Colors now handles Enter on Back itself and gives the list no
onSelect, so digits do nothing, as the handler already intended. Enter on
a widget still does nothing, and Enter on Back and ESC still go back.
With separators shown in Edit Colors, highlighting one and pressing s
again hid it but left the highlight pointing at it. The list redrew with
the marker on the first item, but every key that acts on the highlighted
item looked up the hidden separator and found nothing: b, d, r and
left/right did nothing, a color entered after a, h or g was dropped, and
the "Current foreground" line went blank.

When hiding separators takes away the highlighted one, the highlight now
moves to the first widget, where the list already draws the marker.
Showing separators, or hiding them while a widget is highlighted, keeps
the highlight where it was.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant