* Respect `dircounts` when sorting by size * Avoid mixing file sizes and counts when sorting by size * Update documentation for sorting
This commit is contained in:
1 parent
e5c2cc44d8
commit
4758ef621c
4 files changed
+22
-4
No files matched your search
@@ -759,6 +759,7 @@ This option only has an effect when `info` has a `size` field and the pane is wi
|
||||
## dirfirst (bool) (default true)
|
||||
|
||||
Show directories first above regular files.
|
||||
With `dircounts` enabled, sorting by `size` always separates directories and files, regardless of `dirfirst`.
|
||||
|
||||
## dironly (bool) (default false)
|
||||
|
||||
|
||||
@@ -800,7 +800,9 @@ directory at most, and bigger directories are shown as 999+.
|
||||
|
||||
dirfirst (bool) (default true)
|
||||
|
||||
Show directories first above regular files.
|
||||
Show directories first above regular files. With dircounts enabled,
|
||||
sorting by size always separates directories and files, regardless of
|
||||
dirfirst.
|
||||
|
||||
dironly (bool) (default false)
|
||||
|
||||
|
||||
@@ -707,6 +707,8 @@ information.
|
||||
shown as \f[CR]999+\f[R].
|
||||
.SS dirfirst (bool) (default true)
|
||||
Show directories first above regular files.
|
||||
With \f[CR]dircounts\f[R] enabled, sorting by \f[CR]size\f[R] always
|
||||
separates directories and files, regardless of \f[CR]dirfirst\f[R].
|
||||
.SS dironly (bool) (default false)
|
||||
Show only directories.
|
||||
.SS dirpreviews (bool) (default false)
|
||||
|
||||
@@ -167,6 +167,7 @@ type dir struct {
|
||||
files []*file // displayed files in directory including or excluding hidden ones
|
||||
allFiles []*file // all files in directory including hidden ones (same array as files)
|
||||
sortby sortMethod // sortby value from last sort
|
||||
dircounts bool // dircounts value from last sort
|
||||
dirfirst bool // dirfirst value from last sort
|
||||
dironly bool // dironly value from last sort
|
||||
hidden bool // hidden value from last sort
|
||||
@@ -212,6 +213,7 @@ func normalize(s1, s2 string, ignorecase, ignoredia bool) (string, string) {
|
||||
|
||||
func (dir *dir) sort() {
|
||||
dir.sortby = getSortBy(dir.path)
|
||||
dir.dircounts = getDirCounts(dir.path)
|
||||
dir.dirfirst = getDirFirst(dir.path)
|
||||
dir.dironly = getDirOnly(dir.path)
|
||||
dir.hidden = getHidden(dir.path)
|
||||
@@ -290,11 +292,18 @@ func (dir *dir) sort() {
|
||||
})
|
||||
}
|
||||
case sizeSort:
|
||||
sizeVal := func(f *file) int64 {
|
||||
if f.IsDir() && dir.dircounts {
|
||||
return int64(f.dirCount)
|
||||
}
|
||||
return f.TotalSize()
|
||||
}
|
||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||
s1, s2 := sizeVal(dir.files[i]), sizeVal(dir.files[j])
|
||||
if !dir.reverse {
|
||||
return dir.files[i].TotalSize() < dir.files[j].TotalSize()
|
||||
return s1 < s2
|
||||
} else {
|
||||
return dir.files[j].TotalSize() < dir.files[i].TotalSize()
|
||||
return s2 < s1
|
||||
}
|
||||
})
|
||||
case timeSort:
|
||||
@@ -333,7 +342,9 @@ func (dir *dir) sort() {
|
||||
})
|
||||
}
|
||||
|
||||
if dir.dirfirst {
|
||||
// when sorting by size while also showing dircounts, we always display files
|
||||
// and directories separately to avoid mixing file sizes and file counts
|
||||
if dir.dirfirst || (dir.sortby == sizeSort && dir.dircounts) {
|
||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||
if dir.files[i].IsDir() == dir.files[j].IsDir() {
|
||||
return i < j
|
||||
@@ -538,6 +549,7 @@ func (nav *nav) loadDirInternal(path string) *dir {
|
||||
loadTime: time.Now(),
|
||||
path: path,
|
||||
sortby: getSortBy(path),
|
||||
dircounts: getDirCounts(path),
|
||||
dirfirst: getDirFirst(path),
|
||||
dironly: getDirOnly(path),
|
||||
hidden: getHidden(path),
|
||||
@@ -597,6 +609,7 @@ func (nav *nav) checkDir(dir *dir) {
|
||||
nav.dirChan <- nd
|
||||
}()
|
||||
case dir.sortby != getSortBy(dir.path) ||
|
||||
dir.dircounts != getDirCounts(dir.path) ||
|
||||
dir.dirfirst != getDirFirst(dir.path) ||
|
||||
dir.dironly != getDirOnly(dir.path) ||
|
||||
dir.hidden != getHidden(dir.path) ||
|
||||
|
||||
Reference in new issue
Block a user