From 6fcec86740a69c2f7ff7ce2cce8e8105c6578b4d Mon Sep 17 00:00:00 2001 From: CatsDeservePets <145048791+CatsDeservePets@users.noreply.github.com> Date: Fri, 10 Jul 2026 04:08:16 +0200 Subject: [PATCH] refactor: use `slices.Backward` for reverse iteration (#2639) --- nav.go | 3 +-- ui.go | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/nav.go b/nav.go index 397aab35..776a4973 100644 --- a/nav.go +++ b/nav.go @@ -701,8 +701,7 @@ func (nav *nav) resize(ui *ui) { func (nav *nav) position() { var base string - for i := len(nav.dirPaths) - 1; i >= 0; i-- { - path := nav.dirPaths[i] + for i, path := range slices.Backward(nav.dirPaths) { if i < len(nav.dirPaths)-1 { nav.getDir(path).sel(base, nav.height) } diff --git a/ui.go b/ui.go index d55a0666..6e4c2d0e 100644 --- a/ui.go +++ b/ui.go @@ -563,8 +563,7 @@ func newUI(screen tcell.Screen) *ui { } func (ui *ui) winAt(x, y int) (int, *win) { - for i := len(ui.wins) - 1; i >= 0; i-- { - w := ui.wins[i] + for i, w := range slices.Backward(ui.wins) { if x >= w.x && y >= w.y && y < w.y+w.h { return i, w } @@ -1299,8 +1298,7 @@ func listJumps(jumps []string, ind int) string { t.Init(b, 0, gOpts.tabstop, 2, '\t', 0) fmt.Fprintln(t, " jump\tpath") // print jumps in order of most recent, Vim uses the opposite order - for i := len(jumps) - 1; i >= 0; i-- { - path := jumps[i] + for i, path := range slices.Backward(jumps) { switch { case i < ind: fmt.Fprintf(t, " %*d\t%s\n", maxlength, ind-i, path)