From e4f5907422c5e9f8f398deb56a4b7daa60320a03 Mon Sep 17 00:00:00 2001 From: CatsDeservePets <145048791+CatsDeservePets@users.noreply.github.com> Date: Mon, 23 Mar 2026 02:24:29 +0100 Subject: [PATCH] refactor: simplify `currSelections` (#2455) --- nav.go | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/nav.go b/nav.go index e515e6fb..c8485880 100644 --- a/nav.go +++ b/nav.go @@ -14,7 +14,6 @@ import ( "path/filepath" "regexp" "slices" - "sort" "strconv" "strings" "time" @@ -1938,20 +1937,6 @@ func (nav *nav) currFile() *file { return dir.files[dir.ind] } -type indexedSelections struct { - paths []string - indices []int -} - -func (m indexedSelections) Len() int { return len(m.paths) } - -func (m indexedSelections) Swap(i, j int) { - m.paths[i], m.paths[j] = m.paths[j], m.paths[i] - m.indices[i], m.indices[j] = m.indices[j], m.indices[i] -} - -func (m indexedSelections) Less(i, j int) bool { return m.indices[i] < m.indices[j] } - func (nav *nav) currSelections() []string { currDirOnly := gOpts.selmode == "dir" currDirPath := "" @@ -1961,14 +1946,14 @@ func (nav *nav) currSelections() []string { } paths := make([]string, 0, len(nav.selections)) - indices := make([]int, 0, len(nav.selections)) - for path, index := range nav.selections { + for path := range nav.selections { if !currDirOnly || filepath.Dir(path) == currDirPath { paths = append(paths, path) - indices = append(indices, index) } } - sort.Sort(indexedSelections{paths: paths, indices: indices}) + slices.SortFunc(paths, func(a, b string) int { + return cmp.Compare(nav.selections[a], nav.selections[b]) + }) return paths }