From 309db4d6a8eec03219857bda4076a9bc103ac656 Mon Sep 17 00:00:00 2001 From: HassanFouad <61604840+HassanFouad@users.noreply.github.com> Date: Sun, 3 May 2026 10:06:34 +0300 Subject: [PATCH] fix(tui): add cyclic navigation (#1216) ## What? - Updated the `Update` function in `tui/choice.go` to modify the cursor navigation logic. - Implemented wrap-around (cyclic) navigation for the `up` and `down` keybindings, allowing the cursor to loop seamlessly through the choices. ## Why? - Currently, menu selection stops when reaching the first or last item, requiring users to reverse direction to navigate the list. - Implementing wrap-around navigation solves this problem. Now, moving upward from the first item selects the last item, and moving downward from the last item selects the first item. - This provides a smoother, more natural navigation experience and reduces unnecessary input keystrokes. - closes #1215 --- tui/choice.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tui/choice.go b/tui/choice.go index 2ea375334b8f81bd540e486c014104396579bbb4..df80fa97447e120f53ead73486b197b9e60a87b6 100644 --- a/tui/choice.go +++ b/tui/choice.go @@ -77,13 +77,9 @@ func (m Choice) Update(msg tea.Msg) (tea.Model, tea.Cmd) { kb := config.Keybinds switch msg.String() { case "up", kb.Global.NavUp: - if m.cursor > 0 { - m.cursor-- - } + m.cursor = (m.cursor - 1 + len(m.choices)) % len(m.choices) case "down", kb.Global.NavDown: - if m.cursor < len(m.choices)-1 { - m.cursor++ - } + m.cursor = (m.cursor + 1) % len(m.choices) case "enter": // Use cursor index instead of string comparison idx := m.cursor