From 609c637e8277823ee26ea479b2be8d57ef92d38f Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Fri, 11 Nov 2016 00:18:56 +0300 Subject: [PATCH] move file sorting to nav --- misc.go | 17 ----------------- nav.go | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/misc.go b/misc.go index cb666a95..481541a7 100644 --- a/misc.go +++ b/misc.go @@ -4,7 +4,6 @@ import ( "fmt" "log" "path/filepath" - "sort" "strconv" "strings" "unicode" @@ -158,22 +157,6 @@ func max(a, b int) int { return b } -type filesSortable struct { - files []*File - less func(i, j int) bool -} - -func (f filesSortable) Len() int { return len(f.files) } - -func (f filesSortable) Swap(i, j int) { f.files[i], f.files[j] = f.files[j], f.files[i] } - -func (f filesSortable) Less(i, j int) bool { return f.less(i, j) } - -// TODO: Replace with `sort.SliceStable` once available -func sortFilesStable(files []*File, less func(i, j int) bool) { - sort.Stable(filesSortable{files: files, less: less}) -} - // We don't need no generic code // We don't need no thought control // No dark templates in compiler diff --git a/nav.go b/nav.go index 748c4df7..bcaaed76 100644 --- a/nav.go +++ b/nav.go @@ -7,6 +7,7 @@ import ( "os" "os/exec" "path/filepath" + "sort" "strings" ) @@ -24,6 +25,20 @@ type File struct { Path string } +type FilesSortable struct { + files []*File + less func(i, j int) bool +} + +func (f FilesSortable) Len() int { return len(f.files) } +func (f FilesSortable) Swap(i, j int) { f.files[i], f.files[j] = f.files[j], f.files[i] } +func (f FilesSortable) Less(i, j int) bool { return f.less(i, j) } + +// TODO: Replace with `sort.SliceStable` once available +func sortFilesStable(files []*File, less func(i, j int) bool) { + sort.Stable(FilesSortable{files: files, less: less}) +} + func getFilesSorted(path string) []*File { fi, err := readdir(path) if err != nil {