fix(ui): type j/k in the filter and '?' in the SSH form

In filter mode j/k (any printable key) were matched as Up/Down before the
text input, so a filter for "jpg" became "pg" (QA-3); the arrow keys
and PgUp/PgDn still move through the filtered list.

In the SSH add-host form '?' toggled the help instead of being typed, so
passwords and user names with '?' could not be entered (QA-4). F1 opens
the help; '?' only closes it while it is shown.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vrubelroman 2026-11-01 03:55:32 +03:00
parent e5c6b279f6
commit 2cbc0c3d70
3 changed files with 36 additions and 12 deletions

View file

@ -1004,6 +1004,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// Filter mode: route keys to the filter input
if m.filterMode {
// Printable keys are text for the query, even if they are
// also navigation keys in the browser (j/k): QA-3.
printable := msg.Type == tea.KeyRunes || msg.Type == tea.KeySpace
switch {
case msg.String() == "esc":
log.Printf("[KEY] Filter: Esc — clear filter")
@ -1019,16 +1022,16 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.filterInput.Blur()
m.status = fmt.Sprintf("Filter: %s", m.filterQuery)
return m, nil
case key.Matches(msg, m.keys.Up):
case !printable && key.Matches(msg, m.keys.Up):
m.moveFilteredCursor(-1)
return m, m.loadPreviewCmd()
case key.Matches(msg, m.keys.Down):
case !printable && key.Matches(msg, m.keys.Down):
m.moveFilteredCursor(1)
return m, m.loadPreviewCmd()
case key.Matches(msg, m.keys.PageUp):
case !printable && key.Matches(msg, m.keys.PageUp):
m.moveFilteredCursor(-max(m.bodyHeight()-6, 5))
return m, m.loadPreviewCmd()
case key.Matches(msg, m.keys.PageDown):
case !printable && key.Matches(msg, m.keys.PageDown):
m.moveFilteredCursor(max(m.bodyHeight()-6, 5))
return m, m.loadPreviewCmd()
default:
@ -1566,10 +1569,9 @@ func (m Model) handleModalKey(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
case msg.String() == "shift+tab":
m.ssh.cycleInput(-1)
return m, nil
case key.Matches(msg, m.keys.Help):
m.ssh.showHelp = !m.ssh.showHelp
return m, nil
case msg.String() == "?":
case msg.String() == "f1", m.ssh.showHelp && key.Matches(msg, m.keys.Help):
// '?' is text in the fields (passwords, user names): only F1
// opens the help; '?' still closes it while it is shown (QA-4).
m.ssh.showHelp = !m.ssh.showHelp
return m, nil
default:
@ -6848,10 +6850,10 @@ func renderSSHConnectModal(m Model, palette theme.Palette, width int) string {
}
lines = append(lines, spacer)
// Use hint token renderer to highlight Enter, Esc, F1
if hl, ok := renderModalHintTokens("Enter to confirm · Esc to cancel · F1/? for help", contentWidth, palette, palette.Muted); ok {
if hl, ok := renderModalHintTokens("Enter to confirm · Esc to cancel · F1 for help", contentWidth, palette, palette.Muted); ok {
lines = append(lines, hl)
} else {
lines = append(lines, noteStyle.Render("Enter to confirm · Esc to cancel · F1/? for help"))
lines = append(lines, noteStyle.Render("Enter to confirm · Esc to cancel · F1 for help"))
}
}

View file

@ -61,3 +61,27 @@ func TestQA1TrashFailureOffersPermanentDelete(t *testing.T) {
})
}
}
// QA-3: in the filter j/k are text, while the arrow keys still move the
// cursor through the filtered list.
func TestQA3FilterArrowsStillNavigate(t *testing.T) {
dir := t.TempDir()
for _, n := range []string{"jk1.txt", "jk2.txt", "other.txt"} {
writeFile(t, filepath.Join(dir, n), "x")
}
d := newDriver(t, dir, t.TempDir())
d.Press("/")
d.Type("jk")
if q := cur(t, d).filterQuery; q != "jk" {
t.Fatalf("query %q", q)
}
cursor := func() int { m := cur(t, d); return m.activePane().Cursor }
before := cursor()
d.Press("down")
if cursor() == before {
t.Fatal("down arrow does not move the cursor in filter mode")
}
if q := cur(t, d).filterQuery; q != "jk" {
t.Fatalf("arrow changed the query: %q", q)
}
}

View file

@ -51,7 +51,6 @@ func TestQATextModalsAcceptCommandLetters(t *testing.T) {
// text. j/k are bound to Up/Down inside the filter handler and never reach
// the input.
func TestQAFilterAcceptsJK(t *testing.T) {
t.Skip("BUG QA-3: j and k typed into the filter move the cursor instead of being typed (filter handler matches keys.Up/Down = k/j before the input, model.go:1015-1020); filtering for \"jpg\" yields \"pg\"")
dir := t.TempDir()
writeFile(t, filepath.Join(dir, "photo.jpg"), "x")
writeFile(t, filepath.Join(dir, "notes.txt"), "x")
@ -115,7 +114,6 @@ func TestQASSHFormCyrillicAndLetters(t *testing.T) {
// '?' is a valid password character, but in the SSH form it toggles help.
func TestQASSHFormPasswordQuestionMark(t *testing.T) {
t.Skip("BUG QA-4: '?' (and F1) in the SSH add-host form toggles help instead of being typed; passwords/user names containing '?' cannot be entered (model.go:1563-1568)")
d := newDriver(t, t.TempDir(), t.TempDir())
openSSHAddForm(t, d)
for i := 0; i < 4; i++ {