Commit 4a1152687e

4a1152687e696e4dbd6560da39fec5fe5b684dea

parent: 2857475da0

Unsigned

Wraient <wraient.911@gmail.com> · 2026-07-22 19:56 UTC

Fix: type hjkl into vim search query, not as motions

In VimKeys search mode (after /), printable keys including h/j/k/l append
to the filter like vim's / prompt. Navigation while searching uses arrows
or tab; hjkl only move in normal mode.

Layout: unified · split

internal/logic_regression_test.go +18 −4
@@ -158,17 +158,31 @@ func TestVimKeysNormalModeNavigatesWithoutFiltering(t *testing.T) {
158 t.Fatalf("k should move up, selected=%d", model.selected) 158 t.Fatalf("k should move up, selected=%d", model.selected)
159 } 159 }
160 160
161 // / enters search mode; then typing filters. 161 // / enters search mode; then typing filters — including hjkl as query text.
162 updated, _ = model.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'/'}}) 162 updated, _ = model.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'/'}})
163 model = updated.(*Model) 163 model = updated.(*Model)
164 if !model.filterActive { 164 if !model.filterActive {
165 t.Fatal("expected / to enter search mode") 165 t.Fatal("expected / to enter search mode")
166 } 166 }
167 updated, _ = model.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'B'}}) 167 updated, _ = model.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'j'}})
168 model = updated.(*Model) 168 model = updated.(*Model)
169 if model.filter != "B" { 169 if model.filter != "j" {
170 t.Fatalf("expected filter B in search mode, got %q", model.filter) 170 t.Fatalf("in search mode j should type into query, got filter=%q selected=%d", model.filter, model.selected)
171 }
172 if model.selected != 0 {
173 t.Fatalf("in search mode j must not move selection, selected=%d", model.selected)
174 }
175 updated, _ = model.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'k'}})
176 model = updated.(*Model)
177 if model.filter != "jk" {
178 t.Fatalf("expected filter jk in search mode, got %q", model.filter)
171 } 179 }
180
181 // Arrows still navigate results while searching.
182 updated, _ = model.Update(tea.KeyMsg{Type: tea.KeyDown})
183 model = updated.(*Model)
184 // After filtering to "jk" there may be no matches; selection stays valid either way.
185 _ = model
172} 186}
173 187
174func TestLegacyModeStillTypeToFilter(t *testing.T) { 188func TestLegacyModeStillTypeToFilter(t *testing.T) {
internal/selection_menu.go +13 −6
@@ -149,8 +149,9 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
149 } 149 }
150 150
151 // --- Vim-enabled selection: normal mode vs search mode --- 151 // --- Vim-enabled selection: normal mode vs search mode ---
152 // Normal: hjkl/arrows move. Search (after /): like vim's / — every
153 // printable key including hjkl is part of the query; arrows/tab still move.
152 if vimKeys { 154 if vimKeys {
153 // Search mode: typing filters; j/k/arrows still navigate results.
154 if m.filterActive { 155 if m.filterActive {
155 switch key { 156 switch key {
156 case "esc": 157 case "esc":
@@ -164,11 +165,17 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
164 m.filter = m.filter[:len(m.filter)-1] 165 m.filter = m.filter[:len(m.filter)-1]
165 updateFilter = true 166 updateFilter = true
166 } 167 }
167 case "down", "j", "tab", "ctrl+n", "l", "right": 168 case "down", "tab", "ctrl+n":
168 m.moveSelectionDown() 169 m.moveSelectionDown()
169 case "up", "k", "shift+tab", "ctrl+p", "h", "left": 170 case "up", "shift+tab", "ctrl+p":
170 m.moveSelectionUp() 171 m.moveSelectionUp()
172 // left/right: optional result navigation without stealing hjkl
173 case "left":
174 m.moveSelectionUp()
175 case "right":
176 m.moveSelectionDown()
171 default: 177 default:
178 // hjkl and all other printables go into the search query.
172 if len(key) == 1 && key >= " " && key <= "~" { 179 if len(key) == 1 && key >= " " && key <= "~" {
173 m.filter += key 180 m.filter += key
174 updateFilter = true 181 updateFilter = true
@@ -279,11 +286,11 @@ func (m Model) View() string {
279 // Display the search prompt and filter with colors 286 // Display the search prompt and filter with colors
280 if VimKeysEnabled(nil) { 287 if VimKeysEnabled(nil) {
281 if m.filterActive { 288 if m.filterActive {
282 b.WriteString(titleStyle.Render("Search") + " (Esc: leave search · Enter: select · j/k: move):\n") 289 b.WriteString(titleStyle.Render("Search") + " (type query · arrows move · Enter: select · Esc: normal):\n")
283 b.WriteString(filterLabelStyle.Render("Filter: ") + 290 b.WriteString(filterLabelStyle.Render("/") +
284 filterTextStyle.Render(m.filter+"▌") + "\n\n") 291 filterTextStyle.Render(m.filter+"▌") + "\n\n")
285 } else { 292 } else {
286 b.WriteString(titleStyle.Render("Select") + " (j/k/h/l · / search · Enter · Esc):\n") 293 b.WriteString(titleStyle.Render("Select") + " (hjkl/arrows · / search · Enter · Esc):\n")
287 if m.filter != "" { 294 if m.filter != "" {
288 b.WriteString(filterLabelStyle.Render("Filter: ") + 295 b.WriteString(filterLabelStyle.Render("Filter: ") +
289 filterTextStyle.Render(m.filter) + "\n\n") 296 filterTextStyle.Render(m.filter) + "\n\n")