Skip to content

Commit

Permalink
sort: don't double sort when dirfirst is set
Browse files Browse the repository at this point in the history
In fact, sort after all the filtering is done, makes more sense
  • Loading branch information
q3cpma committed May 8, 2024
1 parent 3e825d8 commit 51144aa
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions nav.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ func (dir *dir) sort() {
return oldlessfun(j, i)
}
}
sort.SliceStable(dir.files, lessfun)

// when dironly option is enabled, we move files to the beginning of our file
// list and then set the beginning of displayed files to the first directory
Expand All @@ -298,12 +297,13 @@ func (dir *dir) sort() {
return dir.files[len(dir.files):]
}()
} else if dir.dirfirst {
sort.SliceStable(dir.files, func(i, j int) bool {
oldlessfun := lessfun
lessfun = func(i, j int) bool {
if dir.files[i].IsDir() == dir.files[j].IsDir() {
return i < j
return oldlessfun(i, j)
}
return dir.files[i].IsDir()
})
}
}

// when hidden option is disabled, we move hidden files to the
Expand Down Expand Up @@ -345,6 +345,9 @@ func (dir *dir) sort() {
}
}

// Finally sort after filtering it all
sort.SliceStable(dir.files, lessfun)

dir.ind = max(dir.ind, 0)
dir.ind = min(dir.ind, len(dir.files)-1)
}
Expand Down

0 comments on commit 51144aa

Please sign in to comment.