fix(ui): Cyrillic text input, PgDn, and q closing layers before quitting

- Russian-layout translation applies only to command keys; mkdir, rename,
  filter and the SSH form receive the typed runes (U-P1-5)
- PgDn is bound (U-P1-6); help text no longer promises an unbound 'b'
- q with the info pane, a filter or a selection closes that layer like
  Esc and quits only from the bare browser; q no longer closes the SSH
  form while typing (U-P1-16, partial)
- smoke tests for PgDn and Cyrillic mkdir are no longer skipped

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vrubelroman 2026-10-31 23:10:42 +03:00
parent 6696fea67a
commit 2ba00b0ad0
5 changed files with 116 additions and 9 deletions

View file

@ -135,10 +135,11 @@ func selectedEntryName(t *testing.T, d *teadriver.Driver) string {
}
// activeOf returns a copy of the active pane.
func activeOf(t *testing.T, d *teadriver.Driver) BrowserPane {
func activeOf(t *testing.T, d *teadriver.Driver) *BrowserPane {
t.Helper()
m := cur(t, d)
return *m.activePane()
p := *m.activePane()
return &p
}
// connectTestHost starts an in-process SSH server and connects the app's

View file

@ -164,7 +164,7 @@ func TestUP02_NoWriteIntoArchivePane(t *testing.T) {
selectName(t, d, "box.zip")
d.Press("enter") // left pane enters the archive
d.Settle(settle)
if p := activeOf(t, d); !p.InArchive() {
if !activeOf(t, d).InArchive() {
t.Fatal("left pane did not enter the archive")
}
d.Press("tab") // right (local) pane active, left (archive) passive
@ -348,3 +348,78 @@ func TestBackgroundPreservingReset(t *testing.T) {
t.Fatalf("got %q %v", got, ok)
}
}
// U-P1-16: "q" quit the program even with the info pane, a filter or a
// selection open; it must close that layer first.
func TestUP116_QClosesInfo(t *testing.T) {
dir := t.TempDir()
writeFile(t, filepath.Join(dir, "a.txt"), "x")
writeFile(t, filepath.Join(dir, "b.txt"), "y")
d := newDriver(t, dir, t.TempDir())
selectName(t, d, "a.txt")
d.Press("f9")
d.Settle(settle)
if !cur(t, d).infoMode {
t.Fatal("info pane did not open")
}
d.Press("q")
d.Settle(settle)
if d.Quit() {
t.Fatal("q with the info pane open quit the program")
}
if cur(t, d).infoMode {
t.Fatal("q did not close the info pane")
}
d.Press("/")
d.Type("a")
d.Press("enter", "q")
d.Settle(settle)
if d.Quit() || cur(t, d).filterQuery != "" {
t.Fatalf("q should clear the filter (quit=%v filter=%q)", d.Quit(), cur(t, d).filterQuery)
}
d.Press("J") // mark an entry
if len(activeOf(t, d).MarkedEntries()) == 0 {
t.Fatal("J did not mark")
}
d.Press("q")
d.Settle(settle)
if d.Quit() || len(activeOf(t, d).MarkedEntries()) != 0 {
t.Fatal("q should clear the selection first")
}
d.Press("q")
d.Settle(settle)
if !d.Quit() {
t.Fatal("q from the bare browser should quit")
}
}
// U-P1-5: Cyrillic in the filter and rename fields stays Cyrillic, while
// commands still work from the Russian layout.
func TestUP15_CyrillicTextAndCommands(t *testing.T) {
dir := t.TempDir()
writeFile(t, filepath.Join(dir, "отчёт.txt"), "x")
writeFile(t, filepath.Join(dir, "other.txt"), "y")
d := newDriver(t, dir, t.TempDir())
d.Press("/")
d.Type("отч")
if q := cur(t, d).filterQuery; q != "отч" {
t.Fatalf("filter query %q", q)
}
d.Press("esc")
selectName(t, d, "other.txt")
d.Press("к") // "r" on the Russian layout: rename
if cur(t, d).modal.kind != modalRename {
t.Fatal("command key on the Russian layout no longer works")
}
d.Press("ctrl+u")
d.Type("новое.txt")
d.Press("enter")
d.Settle(settle)
if !exists(filepath.Join(dir, "новое.txt")) {
t.Fatal("rename with a Cyrillic name failed")
}
}

View file

@ -62,7 +62,7 @@ func DefaultKeyMap() KeyMap {
SelectUp: key.NewBinding(key.WithKeys("shift+up", "K"), key.WithHelp("S-↑/K", "select up")),
SelectDown: key.NewBinding(key.WithKeys("shift+down", "J"), key.WithHelp("S-↓/J", "select down")),
PageUp: key.NewBinding(key.WithKeys("pgup"), key.WithHelp("PgUp", "page up")),
PageDown: key.NewBinding(),
PageDown: key.NewBinding(key.WithKeys("pgdown"), key.WithHelp("PgDn", "page down")),
Filter: key.NewBinding(key.WithKeys("/"), key.WithHelp("/", "filter")),
Open: key.NewBinding(key.WithKeys("enter", "right"), key.WithHelp("Enter", "open")),
Back: key.NewBinding(key.WithKeys("backspace", "left"), key.WithHelp("←", "parent")),

View file

@ -837,7 +837,11 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil
case tea.KeyMsg:
msg = translateKeyMsg(msg)
// Russian-layout letters are mapped to their Latin keys only when
// the key is a command; text fields get the original runes (U-P1-5).
if !m.textInputActive() {
msg = translateKeyMsg(msg)
}
if msg.String() != "y" {
m.pendingY = false
}
@ -1047,6 +1051,12 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
_ = remotePrefix // used in logs below
// "q" first closes whatever layer is open (filter, info pane,
// selection), like Esc; it quits only from the bare browser (U-P1-16).
if msg.String() == "q" && m.hasClosableLayer() {
msg = tea.KeyMsg{Type: tea.KeyEsc}
}
switch {
case key.Matches(msg, m.keys.Quit):
log.Printf("[KEY] Quit — exiting application")
@ -1497,7 +1507,7 @@ func (m Model) handleModalKey(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
case modalSSHConnect:
switch {
case isModalCloseKey(msg, m.keys):
case key.Matches(msg, m.keys.Cancel): // not "q": it is typed into the form
log.Printf("[MODAL] SSH connect — cancelled (Esc)")
m.modal = modalState{}
if m.ssh != nil && m.ssh.testingConn {
@ -1654,6 +1664,29 @@ func (m Model) handleModalKey(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
// isModalNoKey is the "n" answer of yes/no dialogs (their notes promise
// "Esc / n to cancel"). Not used by dialogs with text input.
// textInputActive reports whether keys currently go to a text field.
func (m *Model) textInputActive() bool {
switch m.modal.kind {
case modalMkdir, modalRename, modalSSHConnect:
return true
case modalNone:
return m.filterMode && !m.viewMode
}
return false
}
// hasClosableLayer reports whether Esc/q would close something in browse
// mode instead of doing nothing (Esc) or quitting (q).
func (m *Model) hasClosableLayer() bool {
if m.filterQuery != "" && m.filterPaneID == m.active {
return true
}
if m.infoMode {
return true
}
return len(m.activePane().MarkedEntries()) > 0
}
func isModalNoKey(msg tea.KeyMsg) bool {
return msg.String() == "n" || msg.String() == "N"
}
@ -3173,7 +3206,7 @@ func (m *Model) openHelpModal() {
" k / Up move up",
" Shift+Down/J extend selection down",
" Shift+Up/K extend selection up",
" PgUp / b page up",
" PgUp / PgDn page up / down",
" Enter / Right open selected entry",
" Backspace/Left go to parent directory",
" Tab / h / l switch active pane",

View file

@ -62,7 +62,6 @@ func TestSmokeMkdir(t *testing.T) {
}
func TestSmokeMkdirCyrillic(t *testing.T) {
t.Skip("U-P1-5: fixed in 1.6")
dir := t.TempDir()
d := newDriver(t, dir, t.TempDir())
d.Press("f7")
@ -161,7 +160,6 @@ func TestSmokeDeleteWithConfirm(t *testing.T) {
}
func TestSmokePageDown(t *testing.T) {
t.Skip("U-P1-6: fixed in 1.6")
dir := t.TempDir()
for i := 0; i < 200; i++ {
writeFile(t, filepath.Join(dir, fmt.Sprintf("f%03d", i)), "x")