refactor: simplify currSelections (#2455)
This commit is contained in:
1 parent
3b025160c4
commit
e4f5907422
1 file changed
+4
-19
@@ -14,7 +14,6 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"slices"
|
"slices"
|
||||||
"sort"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -1938,20 +1937,6 @@ func (nav *nav) currFile() *file {
|
|||||||
return dir.files[dir.ind]
|
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 {
|
func (nav *nav) currSelections() []string {
|
||||||
currDirOnly := gOpts.selmode == "dir"
|
currDirOnly := gOpts.selmode == "dir"
|
||||||
currDirPath := ""
|
currDirPath := ""
|
||||||
@@ -1961,14 +1946,14 @@ func (nav *nav) currSelections() []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
paths := make([]string, 0, len(nav.selections))
|
paths := make([]string, 0, len(nav.selections))
|
||||||
indices := make([]int, 0, len(nav.selections))
|
for path := range nav.selections {
|
||||||
for path, index := range nav.selections {
|
|
||||||
if !currDirOnly || filepath.Dir(path) == currDirPath {
|
if !currDirOnly || filepath.Dir(path) == currDirPath {
|
||||||
paths = append(paths, path)
|
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
|
return paths
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user