Skip to content

Commit 898036a

Browse files
committed
Fix the action item in explorer, it should not be sorted
1 parent f38287b commit 898036a

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

menu/menu_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func Test_buildExplorer(t *testing.T) {
114114
os.Create(tmp + "File 1.txt")
115115
os.Create(tmp + "File 2.img")
116116
os.Create(tmp + "File 3.txt")
117-
os.Create(tmp + "File 4.img")
117+
os.Create(tmp + "File 4.img") // this entry will be pushed at the end by sort+prettify
118118
os.Create(tmp + "File 5.txt")
119119
os.Create(tmp + "File 6.txt")
120120
os.Create(tmp + "File 7.txt")
@@ -158,14 +158,14 @@ func Test_buildExplorer(t *testing.T) {
158158
})
159159

160160
t.Run("Targeted files have OK callbacks", func(t *testing.T) {
161-
children[3].callbackOK()
161+
children[2].callbackOK()
162162
if exec != 1 {
163163
t.Errorf("buildExplorer = %v, want %v", exec, 1)
164164
}
165165
})
166166

167167
t.Run("Folders have folder icon", func(t *testing.T) {
168-
if children[4].icon != "folder" {
168+
if children[3].icon != "folder" {
169169
t.Errorf("buildExplorer = %v, want %v", children[4].icon, "folder")
170170
}
171171
})
@@ -174,15 +174,15 @@ func Test_buildExplorer(t *testing.T) {
174174
if len(menu.stack) != 1 {
175175
t.Errorf("buildExplorer = %v, want %v", len(menu.stack), 1)
176176
}
177-
children[4].callbackOK()
177+
children[3].callbackOK()
178178
if len(menu.stack) != 2 {
179179
t.Errorf("buildExplorer = %v, want %v", len(menu.stack), 2)
180180
}
181181
})
182182

183183
t.Run("Prettifier should work", func(t *testing.T) {
184184
want := "IMAGE 4"
185-
if children[3].label != want {
185+
if children[4].label != want {
186186
t.Errorf("buildExplorer = %v, want %v", children[3].label, want)
187187
}
188188
})

menu/scene_explorer.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,15 @@ func buildExplorer(path string, exts []string, cb func(string), dirAction *entry
138138
}
139139

140140
files, err := ioutil.ReadDir(path)
141+
142+
// Sort entries by their labels, ignoring case.
143+
sort.SliceStable(files, func(i, j int) bool {
144+
if prettifier != nil {
145+
return strings.ToLower(prettifier(utils.FileName(files[i].Name()))) < strings.ToLower(prettifier(utils.FileName(files[j].Name())))
146+
}
147+
return strings.ToLower(utils.FileName(files[i].Name())) < strings.ToLower(utils.FileName(files[j].Name()))
148+
})
149+
141150
if err != nil {
142151
ntf.DisplayAndLog(ntf.Error, "Menu", err.Error())
143152
}
@@ -158,11 +167,6 @@ func buildExplorer(path string, exts []string, cb func(string), dirAction *entry
158167
appendNode(&list, fullPath, f.Name(), fi, exts, cb, dirAction, prettifier)
159168
}
160169

161-
// Sort entries by their labels, ignoring case.
162-
sort.SliceStable(list.children, func(i, j int) bool {
163-
return strings.ToLower(list.children[i].label) < strings.ToLower(list.children[j].label)
164-
})
165-
166170
buildIndexes(&list.entry)
167171

168172
if len(files) == 0 {

0 commit comments

Comments
 (0)